Toothless
Toothless

Reputation: 369

How to enter the text into 'textarea' tag using selenium?

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

Upvotes: 0

Views: 8298

Answers (3)

yglodt
yglodt

Reputation: 14551

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

Upvotes: 1

NarendraR
NarendraR

Reputation: 7708

Use This -

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

Upvotes: 0

optimistic_creeper
optimistic_creeper

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

Related Questions