【问题标题】:selenium.JavascriptException: javascript error: Failed to execute 'elementFromPoint' on 'Document': The provided double value is non-finiteselenium.JavascriptException:javascript 错误:无法在“文档”上执行“elementFromPoint”:提供的双精度值是非有限的
【发布时间】:2020-03-18 17:33:00
【问题描述】:

使用 chrome 78 和 chromedriver78 当我单击音频文件或尝试使用 selenium 测试停止音频时,我收到此错误。

错误:

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

请注意,它只发生在远程 webdriver 上,并且不一致。

错误堆栈跟踪:

当“item_1”元素的音频播放器在“[data-rcfid='checkbox_7']”中停止时

org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
  (Session info: chrome=78.0.3904.70)
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ip-10-0-10-137', ip: '10.0.10.137', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-71-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 78.0.3904.70, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: C:\Windows\proxy\scoped_dir...}, goog:chromeOptions: {debuggerAddress: localhost:1674}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept, webdriver.remote.sessionid: eb7d4195af3426c181317a16028...}
Session ID: eb7d4195af3426c181317a160286b15e0125b619
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:611)
    at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
    at webDriver.Driver.click(Driver.java:147)
    at pageObjects.ActivityPageObject.clickAudioInlineStopIn(ActivityPageObject.java:205)
    at stepDefinition.Activity.theAudioPlayerOfTheElementIsStoppedIn(Activity.java:61)
    at ✽.When the audio player of the "item_1" element is stopped in "[data-rcfid='checkbox_7']"(/opt/atlassian/bamboo-home/xml-data/build-dir/16744451/RCF1-RMIT-BROW3/rcf-automation-tests/src/test/resources/featureFiles/interactions/markedInteractions/CheckBox.feature:433)

【问题讨论】:

  • 你能修复它吗?如果是,请在此处添加答案,以便它可以帮助像我这样的人。

标签: selenium selenium-webdriver webdriver selenium-chromedriver selenium-remotedriver


【解决方案1】:

我遇到了同样的问题,观察结果是,同一个 xpath 的多个元素。找到不同的唯一 xpath 解决了它

【讨论】:

  • 我将我的 chrome 版本降级为 chrome 75(这不应该是正确的方法),这是一个快速修复的稳定版本
  • 嗨,根据我的情况,如果有 2 个或多个相同的元素,ID,XPATH,NAME 或任何您使用此错误的方式,那么您可以找到唯一的 xpath 或目标元素通过其他方式,如类,链接文本或文本包含......在 chrome 中检查 Carl+shift +I 然后在 ctrl + f 中搜索,元素的身份应该是唯一的
【解决方案2】:

我遇到了同样的问题,只需将窗口向下滚动到我要定位的元素即可解决它。似乎该元素没有显示在视口中,这就是它对硒不可见的原因。

在找到并单击元素之前尝试添加以下行:

driver.execute_script("window.scrollTo(0, window.scrollY + 100)")
driver.implicitly_wait(3) 

【讨论】:

    【解决方案3】:

    我在尝试单击 AngularJS 网格中的单元格时遇到了同样的问题。我确认我的 XPath 查询只产生了一个结果,然后探讨了添加等待条件是否会有所帮助。事实证明,在这里添加等待允许代码继续而不会出错。

    下面的代码是我用来单击单元格的方法。我从 Click() 切换到 Action,因为 Click() 方法被不同的元素拦截。

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

    WaitConditions 是一个单独的类,用于对已弃用的 ExpectedConditions 包的某些行为进行建模。

    这是上面使用的 WaitConditions 中的方法。

    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;
            }
        };
    }
    

    【讨论】:

      【解决方案4】:

      问题是,您发现了一个未在 Web 浏览器中以图形方式显示的元素 - location 属性的值:X=0 和 Y=0;所以你可能定位到了错误的元素。

      【讨论】:

        【解决方案5】:

        此错误消息...

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

        ...暗示WebDriver 实例由于某种原因无法使用Locator Strategy 找到所需的元素:

        • 定位器策略不会在DOM Tree 中唯一标识所需元素。
        • 当您尝试与之交互时,该元素未正确加载。
        • 元素在&lt;iframe&gt; / &lt;frame&gt;
        • 元素的style属性包含display: none;
        • 元素位于 shadow DOM 中。

        分析

        相关的 HTML 将有助于以更好的方式分析问题。但是,您需要注意以下几点:

        • 确保定位器策略HTML DOM中唯一标识所需元素。

        • WebDriverWait 诱导为elementToBeClickable(),您可以使用以下任一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();
            
        • 如果WebElement&lt;iframe&gt; / &lt;frame&gt; 内,则需要将WebDriverWait 诱导为所需的frameToBeAvailableAndSwitchToIt()

        您可以在Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?找到相关的详细讨论


        参考文献

        您可以在以下位置找到一些相关的详细讨论:

        【讨论】:

          【解决方案6】:

          我也遇到了同样的问题。就我而言,问题是我尝试移动到的元素在浏览器中尚不可见。

          所以我用time.sleep(1)

          之后就成功了。

          【讨论】:

            【解决方案7】:

            当我从 70 年代 (71?) 的版本升级到 ChromeDriver 88 时出现此错误。它实际上是由早期版本的解决方法引起的。这是在角度使用下拉菜单。我不得不移动到该元素,然后在单独的步骤中单击它,而不是单击一个元素。当我删除 moveToElement 步骤时,错误消失了

            之前的代码

                    masterPage.MasterDropDown.click();
                    Thread.sleep(3000);
                    actions.moveToElement(masterPage.MasterDropDown).perform();
                    Thread.sleep(1000);
                    actions.moveToElement(masterPage.DropdownButton1).perform();
                    Thread.sleep(1000);
                    masterPage.DropdownButton1.click();
            

            改为

                    masterPage.MasterDropDown.click();
                    masterPage.DropdownButton1.click();
            

            错误消失了,变得更干净了。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2020-05-08
              • 2021-04-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多