Reputation: 89
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.
Here's the code snippet of the 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"/>
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("Modification Comment TextArea");
Please check out the images attached for more info:
Upvotes: 3
Views: 56634
Reputation: 437
When the text is very long, SendKeys can time out, take a long time or be instable. What might work then is copy the text to the clipboard and then send OpenQA.Selenium.Keys.Control + "v"
to the text area element.
A drawback of this method is that you will need awt or Swing in Java, or System.Windows or System.Windows.Forms in C#.
Upvotes: 1
Reputation: 3687
I make use of the javascript executor.
org.openqa.selenium.JavascriptExecutor.executeScript(String, Object...)
And instead do:
String javascriptToExecute = String.format("document.getElementById('%1$s').value = decodeURI('%2$s'); ",
componentId, uriEcondedValue);
getJavascriptExecutor().executeScript(javascriptToExecute);
Upvotes: 0
Reputation: 89
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");
Thanks
Upvotes: 5