selenium-webdriverjavascriptexecutor

Selenium JavascriptExecutor: Invalid or unexpected token


When trying to use this format of selector with SeleniumJavascriptExecutor:

js.executeScript("arguments[0].textContent=${value}", driver.findElement(By.cssSelector('div.stb-LazyChosenDropdown div.tiles div.input:nth-child(1)')))

The following error is thrown:

org.openqa.selenium.JavascriptException: javascript error: Invalid or unexpected token

Yet it works without the :nth-child(1) part just fine so I'm inclined to think it doesn't like the (1) in the string which my IDE seems to think is an integer


Solution

  • I can't tell what language that is but it should probably look like this:

    js.executeScript("arguments[0].innerText = arguments[1]", element, value)