javascript错误:未能对“文档”执行“elementsFromPoint”:提供的双精度值是非有限的

2024-06-26 14:42:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近将我的chrome版本更新为最新版本,即79.0.3945.130 (Official Build) (64-bit),并从here下载了兼容的chromedriver

我开始面对这个错误。在进行详细调试时,我发现引起问题的Select类。无论我在代码中选择哪个下拉列表,我都会遇到这个问题

下拉列表的HTML如下所示:

<div class="rd-input--wrapper" id="178"> <label for="attribute178">Flavour</label> <select name="super_attribute[178]" data-selector="super_attribute[178]" data-validate="{required:true}" id="attribute178" class="super-attribute-select"> <option value="">Select</option> <option value="27">Chocolate</option> <option value="28">Strawberry</option> </select> </div>

和网页上的下拉列表:

enter image description here

我使用下面的代码来选择一个值

Select s = new Select(getDriver().findElement(By.id("attribute178")));
s.selectByIndex(1);

错误堆栈跟踪

Javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite. (Session info: chrome=79.0.3945.130) Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:24:21.231Z' System info: host: 'ispl_723.test.com', ip: 'fe80:0:0:0:419:64fe:5dea:dae5%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_191' Driver info: com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: /var/folders/qf/x6bn9cgj1rx...}, goog:chromeOptions: {debuggerAddress: localhost:61452}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}

早些时候,我使用的是Chrome75,一切正常。有人面对过这个问题吗?已经在上发布了与此错误相关的问题,因此没有帮助


Tags: infoidtrue列表valueosversion错误
2条回答

在我的例子中,我在每个命令之前都在命令侦听器中使用了new Actions(driver).moveToElement(element).perform();,因此它将焦点移动到正在执行的元素上

这一行导致上述错误。在评论这一点之后,它的工作很好

此错误消息

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

…表示由于一个或其他原因,WebDriver实例无法找到元素:

  • 尝试与元素交互时,该元素未正确加载
  • 元素位于<iframe>/<frame>
  • 元素的style属性包含display: none;
  • 元素位于阴影DOM

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

  • <select>标记的id属性是attribute178,这显然是动态的。所以你需要构造一个动态的Locator Strategy

  • 由于<select>标记的id属性是动态的,因此需要为element_to_be_clickable()诱导WebDriverWait,并且可以使用以下任一Locator Strategies

  • cssSelector

    Select s = new Select(new WebDriverWait(getDriver(), 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("select.super-attribute-select[id^='attribute']"))));
    s.selectByIndex(1);
    
  • xpath

    Select s = new Select(new WebDriverWait(getDriver(), 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//select[@class='super-attribute-select' and starts-with(@id, 'attribute')]"))));
    s.selectByIndex(1);
    

相关问题 更多 >