Python 未能执行';元素自点';在';文件';:提供的双精度值是非有限的

Python 未能执行';元素自点';在';文件';:提供的双精度值是非有限的,python,selenium,selenium-webdriver,webdriver,webdriverwait,Python,Selenium,Selenium Webdriver,Webdriver,Webdriverwait,因此,我对selenium在HTML中单击隐藏导航栏有问题…我需要单击操作按钮,然后单击导出(Excel) 目前,我将其设置为aria labeledby=share,这假设我想要单击导出(CSV)并执行任务(当脚本想要工作时…如果不想,则我会得到下面的错误)。当我尝试设置find\u elements\u by\u css\u selector()或find\u elements\u by\u xpath()并将其指向Export(Excel)时,它不起作用。因此,我目前将其设置为aria l

因此,我对selenium在HTML中单击隐藏导航栏有问题…我需要单击操作按钮,然后单击导出(Excel)

目前,我将其设置为aria labeledby=share,这假设我想要单击导出(CSV)并执行任务(当脚本想要工作时…如果不想,则我会得到下面的错误)。当我尝试设置
find\u elements\u by\u css\u selector()
find\u elements\u by\u 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)
错误:
回溯(最近一次呼叫最后一次):
文件“c:/Users/xxxxx/Desktop/Python/import/export.py”,第53行,在
操作。将\移动到\元素(共享)。单击(共享)。执行()
文件“C:\Anaconda\lib\site packages\selenium\webdriver\common\action\u chains.py”,第80行,执行
self.w3c_actions.perform()
文件“C:\Anaconda\lib\site packages\selenium\webdriver\common\actions\action\u builder.py”,第76行,执行
self.driver.execute(Command.W3C_ACTIONS,enc)
文件“C:\Anaconda\lib\site packages\selenium\webdriver\remote\webdriver.py”,第321行,执行
self.error\u handler.check\u响应(响应)
文件“C:\Anaconda\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.JavascriptException:消息:javascript错误:未能在“文档”上执行“elementsFromPoint”:提供的双精度值是非有限的。
(会话信息: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-当操作可见时

单击操作后,DIV contaner从导航段移出,现在是车身段的一部分

此错误消息

selenium.common.exceptions.JavascriptException: Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
…表示实例无法使用找到所需的元素,原因之一是:

  • 定位器策略不会唯一地标识所需元素

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

    action.move_to_element(share).click(share).perform()
    
  • 元素位于
    /

  • 元素的style属性包含
    显示:无

  • 元素位于


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

  • 确保定位器策略唯一地标识了系统中所需的元素

  • 归纳所有元素的可见性()
,您可以使用以下方法:

您可以在中找到相关的详细讨论


工具书类 您可以在以下内容中找到一些相关的详细讨论:


无论如何,您可以共享网站或html代码?@NicLaforge抱歉,我无法共享链接或代码,因为这是一个内部网站…我可以只共享这两个元素中的一小部分吗?是的,当然,我不明白您为什么需要ActionChains。似乎您必须单击操作菜单才能显示导航菜单。你能在菜单隐藏和显示时提供剪报吗。@NicLaforge我使用ActionChains,因为如果我共享。click()脚本没有点击…至于代码剪报,我已经将其添加到问题中,因为HTML元素相当大。你看过了吗:。您提到菜单将移动到元素外部。从提供的代码中,您正在使用``find_elements``和
index=0
。你查过找到多少元素了吗。我怀疑有两个,你可能点错了?如果是这种情况,您可以改进css_选择器以选择适当元素下的选择器。此外,你确定当它失败时,菜单实际上是打开的吗?如果你能看一下的话,我已经附上了完整的HTML代码图片。我不太熟悉Selenium,这是我第一次使用它。@ShivPatel老实说,从HTML快照构造任何定位器几乎是不可能的。基于文本的HTML帮助我们甚至可以测试代码。特别是在这个问题中,我没有看到包含
操作的
HTML
selenium.common.exceptions.JavascriptException: Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
action.move_to_element(share).click(share).perform()
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()