如何使用 Selenium Webdriver 将文本设置为 TextArea?

如何使用 Selenium Webdriver 将文本设置为 TextArea?

问题描述:

我正在尝试将一些文本设置到 TextArea 中,默认情况下它具有某种文本,单击时会清除该文本,然后您可以为其设置文本,但我可以使用 java 使用 webdriver 执行它.

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 的代码片段:

Here's the code snippet of the TextArea:

这是我迄今为止尝试过的:element 是 TextArea 控件本身:

Here's what I have tried so far: element is the TextArea control itself:

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(修改注释TextArea");

请查看所附图片了解更多信息:

Please check out the images attached for more info:

这对我有用(通过反复试验才知道这一点)-我没有先执行 click(),而是尝试发送 TAB 和 clear 以及值.

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.

element.sendKeys(Keys.TAB);
element.clear();
element.sendKeys("Some Sample Text Here");

谢谢