0
votes

I want to enter the text "ABCD" as shown in the below image of https://translate.google.com/

Tried the following ways but failed.

  1. sendKeys()--failed.

    driver.findElement(By.xpath("//textarea[@id='sourceis']")).sendKeys("ABCD"); driver.findElement(By.xpath("//textarea[@id='source-is']")).sendKeys(Keys.TAB"ABCD");

  2. set the value property using JavaScriptExecutor--failed

    JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById('source-is').setAttribute('value', 'ABCD')");

  3. 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.

textarea field

3
mention the environment like selenium, browser, os and java versions along with the code. with @optimist_creeper code, it is working for me as well - Naveen Kumar R B

3 Answers

1
votes

I don't know how you tried but the following code works:

driver.findElement(By.id("source")).sendKeys("your text to enter");
0
votes

Use This -

driver.findElement(By.id("source")).sendKeys("ABCD");
0
votes

What worked for me in the Selenium IDE Firefox (v68) extension:

  • Command: execute script
  • Target : document.getElementById('message').value = "Testmessage at " + new Date();
  • Value : empty