Selenium Webdriver在不提交表单的情况下输入多行文本 [英] Selenium Webdriver enter multiline text in form without submitting it

查看:316
本文介绍了Selenium Webdriver在不提交表单的情况下输入多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多行文本,当我只是简单地使用sendKeys将整个文本放入表单时,该表单会在每个换行符时提交.

I have a multiline text and when I am simply putting the whole text into a form using sendKeys, the form gets submitted on each line break.

我尝试用换行符将换行符替换为这种方式:

I tried replacing the newline with carriage return this way:

String myText="Some Multiline Text....";
myText=myText.replace("\n","\13");

这只是删除了换行符,我在输出文本中看不到换行符.

This simply removed the newlines and I could not see the newline in output text.

以下内容也不起作用(它还在换行符处提交表单):

Also below did not work(it also submits form at line breaks):

String myText="Some Multiline Text....";
myText=myText.replace("\n","\r");

那么我如何在不提交表单的情况下使用sendkey中的换行符?

So how do I go about with newlines in sendkeys without submitting the form?

推荐答案

这不是硒问题,在文本字段中按Enter键通常会提交表单.通常,您可以通过使用Shift + Enter插入新行来绕过它.试试这个:

This is not a Selenium issue, pressing enter in a text field often submits the form. Usually you can bypass it by using Shift+Enter to insert a new line. Try this:

String myText = "first line\nsecond line";
myText = myText.replace("\n", Keys.chord(Keys.SHIFT, Keys.ENTER));
myElement.sendKeys(myText);

这篇关于Selenium Webdriver在不提交表单的情况下输入多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆