I am getting a cannot focus element error when running my test in chrome and edge in FF it works fine. I have tried posted resolutions but to no avail. I am not sure wha
For future reference, if others run into this issue, make sure you're only finding one element! Chrome tools can be deceiving sometimes when it comes to this. I re-checked my selector in firePath (firefox add-on) and it turned out that I had two matching nodes, even though chrome tools showed me one element.
https://addons.mozilla.org/en-US/firefox/addon/firepath/
The Actions resolution did work after all. I apparently had an extra driver.findElementBy line that should have been commented out as it was a duplicate to something I had moved to another location.
Thanks for your help!!
The chosen answer worked only partially for me. By adding
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(element));
element.clear();
before using the suggested answer, it worked completely!
This is an edited version of the correct answer, as I was unable to just copy paste that code. With the code below you can copy paste it (If the element is found as id):
elem = driver.find_element_by_id("WHATEVER THE ELEMENT ID IS HERE")
actions = ActionChains(driver)
actions.move_to_element(elem)
actions.click()
actions.send_keys("PUT YOUR TEXT IN HERE")
actions.perform()
sendkeys method is the problem as per the stack trace.
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:121)
Please try Actions
class to first focus on the element then send required keys.
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys("SOME DATA");
actions.build().perform();
May be the Xpath you have set is not up to that element level. E.g. if a text box is traversing through Div\div\textarea
then most probably, you are taking only Div\
part. I had the same problem and it got resolved after writing xpath upto textarea
node.