簡體   English   中英

selenium.JavascriptException:javascript 錯誤:無法在“文檔”上執行“elementFromPoint”:提供的雙精度值是非有限的

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

使用 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)

我有同樣的問題,觀察結果是,同一個 xpath 的多個元素。 尋找不同的獨特 xpath 解決了它

我遇到了同樣的問題,只需將 window 向下滾動到我要定位的元素即可解決它。 似乎該元素沒有顯示在視口中,這就是 selenium 看不到它的原因。

在找到並單擊元素之前嘗試添加以下行:

driver.execute_script("window.scrollTo(0, window.scrollY + 100)")
driver.implicitly_wait(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 是一個單獨的 class 到 model 的一些已棄用的 ExpectedConditions package 的行為。

這是上面使用的 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;
        }
    };
}

問題是,您發現 web 瀏覽器中未以圖形方式顯示的元素 - location 屬性的值:X=0 和 Y=0; 所以你可能找到了錯誤的元素。

此錯誤消息...

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

...意味着WebDriver實例由於一個或其他原因無法使用定位器策略找到所需的元素:

  • 定位器策略不會在DOM Tree中唯一標識所需的元素。
  • 當您嘗試與之交互時,該元素未正確加載。
  • 元素在<iframe> / <frame>
  • 元素的 style 屬性包含display: none;
  • 元素位於shadow DOM中。

分析

相關的 HTML 將有助於以更好的方式分析問題。 但是,您需要注意以下幾點:

  • 確保定位器策略HTML DOM中唯一標識所需元素。

  • elementToBeClickable()引入WebDriverWait ,您可以使用以下任一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<iframe> / <frame>內,則需要為所需的frameToBeAvailableAndSwitchToIt()引入WebDriverWait

您可以在Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?


參考

您可以在以下位置找到一些相關的詳細討論:

我也面臨同樣的問題。 就我而言,問題是我試圖移動到的元素在瀏覽器中尚不可見。

所以我使用time.sleep(1)

之后它起作用了。

當我從 70 年代(71?)的版本升級到 ChromeDriver 88 時出現此錯誤。 它實際上是由早期版本的解決方法引起的。 這是使用 angular 中的下拉菜單。 我不得不移動到該元素,然后在單獨的步驟中單擊它,而不是單擊一個元素。 當我刪除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();

錯誤消失了,它更干凈了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM