selenium.JavascriptException: javascript error: Failed to execute 'elementFromPoint' on 'Document': The provided double value is non-finite

后端 未结 7 3117
花落未央
花落未央 2021-02-20 12:40

using chrome 78 and chromedriver78 When i click an audio file or try to stop an audio using selenium tests i am getting this error.

Error:

org.openqa.selen         


        
相关标签:
7条回答
  • 2021-02-20 13:19

    I had same issue and observation was , multiple elements by same xpath. Finding different unique xpath resolved it

    0 讨论(0)
  • 2021-02-20 13:27

    The problem is, that you've found an element that is not graphically displayed in the web browser - location property has value: X=0 and Y=0; so you've probably located a wrong element.

    0 讨论(0)
  • 2021-02-20 13:27

    This error message...

    Javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite
    

    ...implies that the WebDriver instance was unable to find the desired element using the Locator Strategy for one or the other reasons:

    • The locator strategy doesn't identifies the desired element uniquely within the DOM Tree.
    • The element haven't loaded properly when you tried to interact with it.
    • Element is within an <iframe> / <frame>
    • The style attribute of the element contains display: none;
    • Element is within an shadow DOM.

    Analysis

    The relevant HTML would have been helpful to analyze the issue in a better way. However, you need to take care of a couple of things as follows:

    • Ensure that the locator strategy identifies the desired element uniquely within the HTML DOM.

    • Induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

      • cssSelector:

        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("elementCssSelector"))).click();
        
      • xpath:

        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("elementXpath"))).click();
        
    • If the WebElement is within an <iframe> / <frame> you need to induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt().

    You can find a relevant detailed discussion in Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?


    References

    You can find a couple of relevant detailed discussions in:

    • javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite
    0 讨论(0)
  • 2021-02-20 13:28

    I have also faced the same issue. In my case the problem was that the element I tried to move to wasn't visible yet in the browser.

    So I used time.sleep(1)

    After that it worked.

    0 讨论(0)
  • 2021-02-20 13:31

    I experienced this same issue while trying to click a cell in an AngularJS grid. I confirmed that my XPath query resulted in only one result, and then explored if adding in a Wait Condition would help. As it turned out, adding in a Wait here allowed the code to continue without error.

    The below code is the method I used to click the cell. I switched from Click() to an Action as the Click() method was being intercepted by a different element.

    public void ClickEmploymentChangeLogButton()
    {
        Wait.Until(WaitConditions.ElementIsVisibleAndEnabled(EmploymentChangeLogButton));
        Actions actions = new Actions(driver);
        actions.MoveToElement(EmploymentChangeLogButton).Perform();
        actions.MoveToElement(EmploymentChangeLogButton).Click().Perform();
    }
    

    WaitConditions is a separate class to model some of the behaviour of the deprecated ExpectedConditions package.

    Here's the method inside WaitConditions that is used above.

    public static Func<IWebDriver, bool> ElementIsVisibleAndEnabled(IWebElement element)
    {
        return (driver) =>
        {
            try
            {
                return element.Displayed && element.Enabled;
            }
            catch (Exception)
            {
                // If element is null, stale or if it cannot be located
                return false;
            }
        };
    }
    
    0 讨论(0)
  • 2021-02-20 13:35

    I have faced the same issue and was able to resolve it by simply scrolling the window down to the element I am targeting. Seems like the element wasn't showing in the viewport and that's why it wasn't visible to selenium.

    Try to add the following lines before finding and clicking the element:

    driver.execute_script("window.scrollTo(0, window.scrollY + 100)")
    driver.implicitly_wait(3) 
    
    0 讨论(0)
提交回复
热议问题