如何修复“元素不可交互"Python 中的硒错误? [英] How to fix "Element not interactable" Selenium error in Python?

查看:29
本文介绍了如何修复“元素不可交互"Python 中的硒错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图单击一个弹出按钮,但我的代码显示错误:

<块引用>

selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互".

我已经搜索过,但找不到对我有用的弹出按钮的解决方案.

点击图片显示10行并显示弹出框附件图像是所需的结果,显示 10 行"在其后面,可以轻松看到.

我的 HTML 代码中有这个,需要点击按钮.

<ul class="nav nav-tabs"><li class="active"><a data-toggle="tab" id="loadsur" href="#Section" aria-expanded="true">LoadSurvey</a></li><div class="container-fluid"><div class="row"><div class="col-md-12" style="margin-left: -10px;"><div class="table-responsive"><div id="myDataTable25_wrapper" class="dataTables_wrapper no-footer"><div class="dt-buttons"><button class="dt-button buttons-csv buttons-html5" tabindex="0" aria-controls="myDataTable25"><span>Csv</span></button><button class="dt-button button-excel buttons-html5" tabindex="0" aria-controls="myDataTable25"><span>Excel</span></button><button class="dt-button button-collection buttons-page-length" tabindex="0" aria-controls="myDataTable25" aria-haspopup="true"><span>显示 10 行</span></button>

在 Python 中我试过这个:

def single_meter(i=0):browser=webdriver.Chrome('C:\Webdrivers\chromedriver.exe')对于范围 (5,10) 中的行:browser.get('http://#link'+consumer_ID+'?reportrange=21%2F07%2F2018-25%2F08%2F2019')Show10 = find_element_by_xpath("//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]")Show10.click()

我希望点击这个按钮会导致一个弹出按钮出现.

解决方案

我得到了这个问题的解决方案.错误与 xpath 中的链接有关.我后来从 html 中复制并粘贴,代码现在看起来是这样的:

Show10 = find_element_by_xpath("//*[@id='myDataTable2_wrapper']/div[1]/button[7]/span")Show10.click()

而且它工作正常.感谢大家的帮助.

I was trying to click a popup button and my code shows the error:

"selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable".

I have searched but could not find the solution which works for me with the popup buttons.

Image for clicking show 10 rows and displaying the pop-up boxThe attached image is the desired result and 'Show 10 rows' is behind it and lightly seen.

I have this in my HTML code and need to click on the button.

<div class="table-responsive">
<ul class="nav nav-tabs">
    <li class="active"><a data-toggle="tab" id="loadsur" href="#Section" aria-expanded="true">LoadSurvey</a></li>
</ul>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12" style="margin-left: -10px;">
            <div class="table-responsive">
                <div id="myDataTable25_wrapper" class="dataTables_wrapper no-footer"><div class="dt-buttons">
                <button class="dt-button buttons-csv buttons-html5" tabindex="0" aria-controls="myDataTable25">
                   <span>Csv</span></button> 
                <button class="dt-button buttons-excel buttons-html5" tabindex="0" aria-controls="myDataTable25">
                   <span>Excel</span></button> 
                <button class="dt-button buttons-collection buttons-page-length" tabindex="0" aria-controls="myDataTable25" aria-haspopup="true">
                   <span>Show 10 rows</span></button> 
                </div>
            </div>
        </div>
    </div>
</div>

In Python I tried this:

def single_meter(i=0):
browser=webdriver.Chrome('C:\Webdrivers\chromedriver.exe')
for row in range (5,10):
    browser.get('http://#link'+consumer_ID+'?reportrange=21%2F07%2F2018-25%2F08%2F2019')
        Show10 = find_element_by_xpath("//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]")
    Show10.click()

I expect to click this button which causes a popup button to appear.

解决方案

I got a solution to this problem. The error was with the link in the xpath. I later copied and pasted from the html and the code now looks this:

Show10 = find_element_by_xpath("//*[@id='myDataTable2_wrapper']/div[1]/button[7]/span")
Show10.click()

And it works fine. Thank all for your help.

这篇关于如何修复“元素不可交互"Python 中的硒错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆