getting cannot focus element in chrome and edge using java/selenium

后端 未结 7 2187
南笙
南笙 2020-12-06 05:26

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

相关标签:
7条回答
  • 2020-12-06 05:53

    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/

    0 讨论(0)
  • 2020-12-06 05:57

    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!!

    0 讨论(0)
  • 2020-12-06 05:58

    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!

    0 讨论(0)
  • 2020-12-06 05:59

    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()
    
    0 讨论(0)
  • 2020-12-06 06:03

    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();
    
    0 讨论(0)
  • 2020-12-06 06:05

    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.

    0 讨论(0)
提交回复
热议问题