My javascript line:
$('#name').show();
My webdriver code line:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("name"))).sendKeys("Some Name");
When I run the test it throws the following exception:
WebDriverException: unknown error: cannot focus element
So, I have been searching for a solution. There are some issues reported in chromium google code site. There are a lot of suggestions about using JavaScriptExecutor
. But it doesn't seem a better solution for me, because it could make a browser dependent code.
After some hours I finally found a solution by using Actions without JavascriptExecuter:
Actions actions = new Actions(driver);
actions.moveToElement(website);
actions.click();
actions.sendKeys("Some Name");
actions.build().perform();
Well, it worked for me. However, is this way the better solution ?
A bit late to the party, but those looking for a solution to this problem while using selenium under python can use the following code:
actions = webdriver.ActionChains(driver)
actions.move_to_element(my_div)
actions.click()
actions.send_keys("Some name") # Replace with whichever keys you want.
actions.perform()
Where my_div
is an element you've previously selected, perhaps with code like this:
my_div = item.find_element_by_css_selector("div.foobar")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With