python - 无法在 'elementsFromPoint' : The provided double value is non-finite 上执行 'Document'

标签 python selenium selenium-webdriver webdriver webdriverwait

所以我在使用 selenium 单击 HTML 中隐藏的导航栏时遇到问题...我需要单击操作按钮,然后单击导出 (Excel)。

目前,我将其设置为 aria-labeledby=share,这假设我想单击导出 (CSV) 并执行任务(当脚本想要工作时……如果不是,则会出现以下错误)。当我尝试设置 find_elements_by_css_selector()find_elements_by_xpath() 并将其指向 Export(Excel) 时,它不起作用。所以我目前将它设置为 aria-labeledby=Share 并且这有效但随机它会停止工作并且我会收到以下错误。在检查网页元素之前,我从未听说过将 WAI-Aria 嵌入到 HTML 中。

action = ActionChains(driver)

aria_lablededBy = driver.find_elements_by_css_selector("[aria-labeledby=Actions]")[0]

action.move_to_element(aria_lablededBy).click(aria_lablededBy).perform()

share = driver.find_elements_by_css_selector('[aria-labeledby=Share]')[0]

action.move_to_element(share).click(share).perform()

上面的代码工作然后随机停止,我得到这个错误消息

ERROR:
    Traceback (most recent call last):
      File "c:/Users/xxxxx/Desktop/Python/import/export.py", line 53, in <module>
        action.move_to_element(share).click(share).perform()
      File "C:\Anaconda\lib\site-packages\selenium\webdriver\common\action_chains.py", line 80, in perform
        self.w3c_actions.perform()
      File "C:\Anaconda\lib\site-packages\selenium\webdriver\common\actions\action_builder.py", line 76, in perform
        self.driver.execute(Command.W3C_ACTIONS, enc)
      File "C:\Anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "C:\Anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.JavascriptException: Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
      (Session info: chrome=87.0.4280.88)

我正在连接的 HTML 站点有 Aria-HTML 代码,我对此并不熟悉。我删除了共享变量和共享变量上的以下操作,脚本将打开操作导航...一旦启用共享变量和操作,它就会给我错误

我在这个问题上出类拔萃,所以如果社区中有人知道如何解决这个问题,我非常感兴趣。

HTML 代码 - 隐藏操作菜单

<lp-mega-menu _ngcontent-iyn-c45="" _nghost-iyn-c31="">
  <nav _ngcontent-iyn-c31="" class="dropdown" lpmegamenu="" role="menu" triggers="manual" id="KJ0X5NWLXZGZ8" aria-labeledby="Actions">
    <button _ngcontent-iyn-c31="" aria-haspopup="true" tabindex="0" type="button" class="lp-themed-button lp-themed-primary-button" aria-controls="dropdown-menu-KJ0X5NWLXZGZ8" aria-expanded="false">
      <!----><!----><!----><span _ngcontent-iyn-c31="">Actions</span><i _ngcontent-iyn-c31="" class="fas fa-caret-down mr-0 ml-default-half"></i>
    </button>
    <div _ngcontent-iyn-c31="" class="dropdown-menu dropdown-menu-right mega-menu-panel my-2" id="dropdown-menu-KJ0X5NWLXZGZ8" aria-hidden="true" style="max-height: 600px;">
      <!---->
      <div _ngcontent-iyn-c31="" class="mega-menu-panel-wrapper label-reset ul-reset">
        <!----><!----><!---->
        <div _ngcontent-iyn-c31="" class="mega-menu-grid">
          <!----><!----><!---->
          <div _ngcontent-iyn-c31="" class="mega-menu-col">
            <div _ngcontent-iyn-c31="" class="mega-menu-body">
              <label _ngcontent-iyn-c31="">Authoring</label>
              <div _ngcontent-iyn-c31="" class="mega-menu-content">
                <ul _ngcontent-iyn-c31="" aria-labeledby="Authoring">
                  <!---->
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Add Record"><span _ngcontent-iyn-c31="">Add</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Filter Report"><span _ngcontent-iyn-c31="">Filters (0)</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Edit Report"><span _ngcontent-iyn-c31="">Edit</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Copy Report"><span _ngcontent-iyn-c31="">Copy</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Delete Report"><span _ngcontent-iyn-c31="">Delete</span></a><!---->
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <!---->
          <div _ngcontent-iyn-c31="" class="mega-menu-col">
            <div _ngcontent-iyn-c31="" class="mega-menu-body">
              <label _ngcontent-iyn-c31="">Bulk Ops</label>
              <div _ngcontent-iyn-c31="" class="mega-menu-content">
                <ul _ngcontent-iyn-c31="" aria-labeledby="Bulk Ops">
                  <!---->
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Edit Records"><span _ngcontent-iyn-c31="">Edit</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Move Records"><span _ngcontent-iyn-c31="">Move</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Edit/Move Records"><span _ngcontent-iyn-c31="">Edit/Move</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Delete Records"><span _ngcontent-iyn-c31="">Delete</span></a><!---->
                  </li>
                </ul>
              </div>
            </div>
          </div>
          <!---->
          <div _ngcontent-iyn-c31="" class="mega-menu-col-md">
            <!----><!----><!---->
            <div _ngcontent-iyn-c31="" class="mega-menu-body">
              <label _ngcontent-iyn-c31="">Share</label>
              <div _ngcontent-iyn-c31="" class="mega-menu-content">
                <ul _ngcontent-iyn-c31="" aria-labeledby="Share">
                  <!---->
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Print a PDF"><span _ngcontent-iyn-c31="">Print (PDF)</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Export as Excel"><span _ngcontent-iyn-c31="">Export (Excel)</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Export as CSV"><span _ngcontent-iyn-c31="">Export (CSV)</span></a><!---->
                  </li>
                  <li _ngcontent-iyn-c31="">
                    <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Copy Report Link"><span _ngcontent-iyn-c31="">Link</span></a><!---->
                  </li>
                </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!---->
    </div>
  </nav>
</lp-mega-menu>

HTML 代码 - 操作菜单可见

<lp-mega-menu _ngcontent-iyn-c45="" _nghost-iyn-c31="">
  <nav _ngcontent-iyn-c31="" class="dropdown open" lpmegamenu="" role="menu" triggers="manual" id="KJ0X5NWLXZGZ8" aria-labeledby="Actions">
    <button _ngcontent-iyn-c31="" aria-haspopup="true" tabindex="0" type="button" class="lp-themed-button lp-themed-primary-button" aria-controls="dropdown-menu-KJ0X5NWLXZGZ8" aria-expanded="true">
      <!----><!----><!----><span _ngcontent-iyn-c31="">Actions</span><i _ngcontent-iyn-c31="" class="fas fa-caret-down mr-0 ml-default-half"></i>
    </button>
  </nav>
</lp-mega-menu>

下面是 HTML 的一部分 - 操作菜单隐藏代码,但一旦菜单可见,代码就会移到此元素之外:

<div _ngcontent-iyn-c31="" class="dropdown-menu dropdown-menu-right mega-menu-panel my-2" id="dropdown-menu-KJ0X5NWLXZGZ8" aria-hidden="false" style="max-height: 600px; display: block; height: 252px; right: 8px; top: 128px;">
<!---->
<div _ngcontent-iyn-c31="" class="mega-menu-panel-wrapper label-reset ul-reset">
  <!----><!----><!---->
  <div _ngcontent-iyn-c31="" class="mega-menu-grid">
    <!----><!----><!---->
    <div _ngcontent-iyn-c31="" class="mega-menu-col">
      <div _ngcontent-iyn-c31="" class="mega-menu-body">
        <label _ngcontent-iyn-c31="">Authoring</label>
        <div _ngcontent-iyn-c31="" class="mega-menu-content">
          <ul _ngcontent-iyn-c31="" aria-labeledby="Authoring">
            <!---->
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Add Record"><span _ngcontent-iyn-c31="">Add</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Filter Report"><span _ngcontent-iyn-c31="">Filters (0)</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Edit Report"><span _ngcontent-iyn-c31="">Edit</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Copy Report"><span _ngcontent-iyn-c31="">Copy</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Delete Report"><span _ngcontent-iyn-c31="">Delete</span></a><!---->
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!---->
    <div _ngcontent-iyn-c31="" class="mega-menu-col">
      <div _ngcontent-iyn-c31="" class="mega-menu-body">
        <label _ngcontent-iyn-c31="">Bulk Ops</label>
        <div _ngcontent-iyn-c31="" class="mega-menu-content">
          <ul _ngcontent-iyn-c31="" aria-labeledby="Bulk Ops">
            <!---->
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Edit Records"><span _ngcontent-iyn-c31="">Edit</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Move Records"><span _ngcontent-iyn-c31="">Move</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Edit/Move Records"><span _ngcontent-iyn-c31="">Edit/Move</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Bulk Delete Records"><span _ngcontent-iyn-c31="">Delete</span></a><!---->
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!---->
    <div _ngcontent-iyn-c31="" class="mega-menu-col-md">
      <!----><!----><!---->
      <div _ngcontent-iyn-c31="" class="mega-menu-body">
        <label _ngcontent-iyn-c31="">Share</label>
        <div _ngcontent-iyn-c31="" class="mega-menu-content">
          <ul _ngcontent-iyn-c31="" aria-labeledby="Share">
            <!---->
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Print a PDF"><span _ngcontent-iyn-c31="">Print (PDF)</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Export as Excel"><span _ngcontent-iyn-c31="">Export (Excel)</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Export as CSV"><span _ngcontent-iyn-c31="">Export (CSV)</span></a><!---->
            </li>
            <li _ngcontent-iyn-c31="">
              <!----><a _ngcontent-iyn-c31="" class="lp-theme-link-focus lp-theme-link-hover lp-theme-link-active" tabindex="0" title="Copy Report Link"><span _ngcontent-iyn-c31="">Link</span></a><!---->
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</div>
<!----></div

完整的 HTML - 当 Action 被隐藏时 enter image description here 您会看到第二个方 block 包含有关下拉菜单的信息,并且位于 Nav 部分下方

完整的 HTML - 当操作可见时 enter image description here

一旦您点击操作,DIV 容器就会移出 Nav 部分,现在是 Body 部分的一部分

最佳答案

这个错误信息...

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

...暗示WebDriver实例无法使用 Locator Strategy 找到所需的元素出于一个或另一个原因:

  • 定位器策略 未在 DOM Tree 中唯一标识所需元素.

  • 当您尝试使用以下行与其进行交互时,该元素不是可交互:

    action.move_to_element(share).click(share).perform()
    
  • 元素在 <iframe> 中/<frame>

  • 元素的style属性包含 display: none;

  • 元素在 shadow DOM 中.


分析

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

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

  • 诱导 WebDriverWait对于 visibility_of_all_elements_located()您可以使用以下 Locator Strategy :

    share = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "span.movie-rating-summary>span")))[0]
    ActionChains(driver).move_to_element(share).click(share).perform()
    

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?


引用资料

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

关于python - 无法在 'elementsFromPoint' : The provided double value is non-finite 上执行 'Document',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65418769/

相关文章:

R Selenium右键单击下载文件

java - RunnerClass 找不到步骤?

python - Selenium :无法下载文件

python - opencv Python人脸识别器.load

python - 将给定 .csv 文件中的现有值替换为 NAN

python - windows下flask 404错误

xpath - css/xpath选择器,用于在使用Selenium Webdriver(java)时排除元素中的子节点

python - Z3 字符串/字符异或?

java - 使用 Java 的 Selenium - 无法在 Google 搜索页面上找到 Webelements

javascript - 适用于多种浏览器的 Selenium - 需要可以执行 javascript 的 webDriver