Reputation: 369
I want to enter the text "ABCD" as shown in the below image of https://translate.google.com/
Tried the following ways but failed.
sendKeys()--failed.
driver.findElement(By.xpath("//textarea[@id='sourceis']")).sendKeys("ABCD"); driver.findElement(By.xpath("//textarea[@id='source-is']")).sendKeys(Keys.TAB"ABCD");
set the value property using JavaScriptExecutor--failed
JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById('source-is').setAttribute('value', 'ABCD')");
first clear() field and then sendKeys()--failed.
driver.findElement(By.xpath("//textarea[@id='source-is']")).clear(); driver.findElement(By.xpath("//textarea[@id='source-is']")).sendKeys(Keys.TAB,"ABCD");
Please provide the solution to get it done.
Upvotes: 0
Views: 8298
Reputation: 14551
What worked for me in the Selenium IDE Firefox (v68) extension:
execute script
document.getElementById('message').value = "Testmessage at " + new Date();
Upvotes: 1
Reputation: 7708
Use This -
driver.findElement(By.id("source")).sendKeys("ABCD");
Upvotes: 0
Reputation: 2799
I don't know how you tried but the following code works:
driver.findElement(By.id("source")).sendKeys("your text to enter");
Upvotes: 1