所以我对selenium在HTML中点击隐藏导航栏有问题。。。我需要单击操作按钮,然后单击导出(Excel)。
目前,我将其设置为aria labeledby=share,这假设我想要单击导出(CSV)并执行任务(当脚本想要工作时……如果没有,则我会得到下面的错误)。当我试图设置find_elements_by_css_selector()
或find_elements_by_xpath()
并将其指向Export(Excel)时,它不起作用。所以我现在把它设置为aria labeledby=Share,这可以正常工作,但它会随机停止工作,我会得到下面的错误。在检查网页元素之前,我从未听说过嵌入HTML的WAI Aria。
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-Action菜单隐藏代码的一部分,但一旦菜单可见,代码就会移到该元素之外:
<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
点击操作后,DIV连接器将移出导航段,现在是正文段的一部分
此错误消息。。。
selenium.common.exceptions.JavascriptException: Message: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
...表示WebDriver实例无法使用定位器策略找到所需的元素,原因之一是:
>
当您尝试使用以下行与元素交互时,该元素无法交互:
action.move_to_element(share).click(share).perform()
元素位于
元素的style属性包含
display:none
元素位于阴影DOM中。
相关的HTML将有助于更好地分析问题。但是,您需要注意以下几件事:
>
确保定位器策略在超文本标记语言DOM中唯一地标识所需的元素。
引导WebDriverWait查看所有元素的可见性()
,您可以使用以下定位策略:
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()
您可以在中找到相关的详细讨论:是否可以在不使用驱动程序的情况下切换到帧中的元素。切换到()。Selenium Webdriver Java中的框架(“框架名”)?
你可以在以下网站上找到一些相关的详细讨论:
javascript错误:未能在“文档”上执行“elementsFromPoint”:提供的双精度值是非有限的
使用Chrome78和chromedriver78当我单击音频文件或尝试使用selenium tests停止音频时,我遇到此错误。 错误: 请注意,这种情况只发生在远程webdriver上,并且不一致。 错误堆栈跟踪: 当“item_1”元素的音频播放器在“[data rcfid='checkbox_7']中停止时
我最近更新了我的chrome版本,即,并从这里下载了兼容的chromedriver 我已经开始面对这个错误了。在详细调试时,我发现类导致了这个问题。无论我在代码中选择一个下拉菜单,我都会遇到这个问题。 下拉列表的HTML如下代码片段所示: 我使用下面的代码来选择一个值 错误stacktrace Javascript错误:在“Document”上执行“Elements frompoint”失败:提供
问题内容: 我正在编写一个简单的Java程序。我需要从输入中获取一个字符串并将其分为两部分:1-double 2-string。然后,我需要对double进行简单的计算,并将结果发送到具有特定精度的输出(4)。它工作正常,但是当输入为0时出现问题,则不能正常工作。 例如,对于这些输入,输出将是: 1公斤 输出:2.2046 3.1公斤 输出:6.8343 但是当输入为0时,输出应为0.0000,但
问题内容: 如何使用正则表达式从字符串中提取双精度值。 问题答案: 这是简单的方法。请勿将regex用于内置类型。
问题内容: 如何使用正则表达式从字符串中提取双精度值。 问题答案: 是简单的方法。请勿将regex用于内置类型。
问题内容: 我正在尝试通过其score属性的值(是double值)对自定义类染色体进行排序。这些染色体存储在ArrayList中。我知道我必须使用比较器,但是在过去的一个小时里我已经在线阅读了很多不同的观点,这使我感到非常困惑。 附上我的代码,如果有人可以指出正确的方向,我将不胜感激。 不知道这有什么区别,但是分数只能是0.0到1.0之间(包括0.0到1.0)的两倍 问题答案: 要使用: 如果您打