2

I need to put the cursor in the textarea element using Selenium. The element has no ID. I have tried:

eventDriver.findElement(By.cssSelector("textarea[class*=\"CodeMirror\"")).click();

and it throws NoSuchElementException

enter image description here

Web Page and underlying code

Andersson
  • 51,635
  • 17
  • 77
  • 129
nicomp
  • 4,344
  • 4
  • 27
  • 60

1 Answers1

4

textarea has no @class - it's an attribute of ancestor div. Try below code instead:

eventDriver.findElement(By.cssSelector("div.CodeMirror textarea")).click();

or with ExplicitWait:

WebDriverWait wait = new WebDriverWait(eventDriver,10);

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.CodeMirror textarea"))).click();

Update

WebElement element = eventDriver.findElement(By.cssSelector("div.CodeMirror textarea"))
JavascriptExecutor jse = ((JavascriptExecutor)eventDriver);
jse.executeScript("arguments[0].click()", element);
Andersson
  • 51,635
  • 17
  • 77
  • 129