Java 如何使用 Selenium Webdriver 将文本设置为 TextArea?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35126293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set text into TextArea with Selenium Webdriver?
提问by AmeetV27
I am trying to set some Text into the TextArea which has some kind of text to it by default which when clicked clears out and then you can set text to it, but I'm enable to perform it with webdriver using java.
我正在尝试将一些文本设置到 TextArea 中,默认情况下该文本具有某种文本,单击时会清除该文本,然后您可以为其设置文本,但我可以使用 java 使用 webdriver 执行它。
Here's the code snippet of the TextArea:
这是 TextArea 的代码片段:
<textarea id="gwt-uid-13" class="v-textarea v-widget v-textarea-required v-required v-has-width v-textarea-prompt" aria-labelledby="gwt-uid-12" aria-required="true" rows="5" tabindex="0" style="width: 600px;" maxlength="4000"/>
<textarea id="gwt-uid-13" class="v-textarea v-widget v-textarea-required v-required v-has-width v-textarea-prompt" aria-labelledby="gwt-uid-12" aria-required="true" rows="5" tabindex="0" style="width: 600px;" maxlength="4000"/>
Here's What I've tried so far: element is the TextArea control itself:
这是我到目前为止所尝试的: element 是 TextArea 控件本身:
element= driver.findElement(By.id("gwt-uid-13"))
element.clear();
element.sendKeys("Modification Comment TextArea");
Also, I tried first clicking the element too,
另外,我也尝试先单击该元素,
element.click();
element.clear();
element.sendKeys("Modification Comment TextArea");
element.click();
element.clear();
element.sendKeys("Modification Comment TextArea");
please check-out the images attached for more info:
请查看所附图片了解更多信息:
Thank you
谢谢
回答by AmeetV27
This is something that works for me (got to know this with trial and error) - instead of performing click() first, I tried sending TAB and clear and the value.
这对我有用(通过反复试验来了解这一点) - 我没有先执行 click() ,而是尝试发送 TAB 和 clear 以及值。
element.sendKeys(Keys.TAB);
element.clear();
element.sendKeys("Some Sample Text Here");
Thanks
谢谢