本文介绍了元素不可点击,因为另一个元素在python中将其遮盖了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动化接入点Web配置.在此过程中,我要单击一个弹出窗口(带有是"和否"的叠加层)

I am trying to automate an access point web configuration. During this, I get a pop up (kind of an overlay with "Yes" and "No") which i want to click on

我要单击的叠加层的HTML代码:

The HTML code for the overlay that I am trying to click on:

<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>

我尝试了

browser.find_element_by_class_name("submit").click()

但出现以下错误:

能否请您告知我应该如何进行?我正在使用firefox和python

Can you please advise on how should i proceed?I am using firefox and python

推荐答案

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

As per your question and the HTML you have shared, you need to induce WebDriverWait for the desired element to be clickable and you can use the following solution:

#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()

注意:您必须添加以下导入:

Note : You have to add the following imports :

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

这篇关于元素不可点击,因为另一个元素在python中将其遮盖了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:31