Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
元素不可单击,因为另一个元素在python中使其模糊_Python_Selenium_Firefox_Ui Automation - Fatal编程技术网

元素不可单击,因为另一个元素在python中使其模糊

元素不可单击,因为另一个元素在python中使其模糊,python,selenium,firefox,ui-automation,Python,Selenium,Firefox,Ui Automation,我正在尝试自动化访问点web配置。在这期间,我得到一个弹出窗口(有点像是“是”和“否”的叠加),我想点击它 我尝试单击的覆盖的HTML代码: <div id="generic-warning-dialog" class="dialog exclamation text-orphan" style=""> <div class="warning-content dialog-content text-orphan">Security Mode is disabled on

我正在尝试自动化访问点web配置。在这期间,我得到一个弹出窗口(有点像是“是”和“否”的叠加),我想点击它

我尝试单击的覆盖的HTML代码:

<div id="generic-warning-dialog" class="dialog exclamation text-orphan" style="">
<div class="warning-content dialog-content text-orphan">Security Mode is disabled on one or more of your wireless networks. Your network could be open to unauthorized users. Are you sure you wish&nbsp;to&nbsp;proceed?</div>
    <div class="dialog-buttons text-orphan">
        <button class="cancel">No</button>
        <button class="submit" style="display: block;">Yes</button>
    </div>
</div> 
但我得到了以下错误:

引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.Element ClickInterceptedException:消息: 元素不是 可在点(788636.5)处单击,因为另一个元素 掩盖它

你能告诉我该怎么做吗?
我正在使用firefox和python

您可以用action类替换click事件

使用动作类:

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.move_to_element("Your Web Element").click().perform()

根据您的问题和您共享的HTML,您需要引导WebDriverWait使所需元素可单击,并且您可以使用以下解决方案:

#to click on Yes button
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='warning-content dialog-content text-orphan' and contains(.,'Security Mode is disabled')]//following::div[1]//button[@class='submit']"))).click()
# to click on No button
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='warning-content dialog-content text-orphan' and contains(.,'Security Mode is disabled')]//following::div[1]//button[@class='cancel']"))).click()
注意:您必须添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

可能重复尝试在单击元素之前给予显式等待。显式等待有何帮助?我通过python控制台尝试了它,给出了每个单独的命令,因此我认为这与页面没有加载无关。这是Selenium和Firefox的一个问题。对于“您的web元素”,我使用了>>>元素=浏览器。通过类名称(“提交”)>>>操作=操作链(浏览器)>>>操作查找元素。将元素移动到元素(元素)。单击().perform()正确吗?这是不可能的work@Klot是的,没错。如果不工作,什么是异常?没有收到任何错误,但无法单击按钮。执行此操作后仍显示覆盖窗口。我收到此错误WebDriverWait(浏览器,20)。直到(EC.element)可单击((By.XPATH,“//div[@class='warning-content dialog content text孤儿”并包含(,'Security Mode is disabled')]//按钮[@class='submit']”)。单击()回溯(最近一次调用):文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/support/wait.py”第80行中的文件“”,直到引发TimeoutException(消息、屏幕、堆栈跟踪)@Klot签出我的更新答案,并让我知道@DebanjanB对答案的投票状态。你能解释一下该命令是如何执行的吗works@Klot在我的解决方案中,我让服务员等待元素变为可点击,一旦元素的状态变得难以处理,我们调用
click()< /代码>方法直接。如果你有任何进一步的疑问,请告诉我。这对我来说不起作用。好像按钮已经“可点击”,但点击它仍然会导致“模糊错误”——在我的例子中,它是基础揭示/模式中的按钮(见)有什么想法吗?
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC