Klo*_*lot 3 python firefox selenium 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 one or more of your wireless networks. Your network could be open to unauthorized users. Are you sure you wish to proceed?</div>
<div class="dialog-buttons text-orphan">
<button class="cancel">No</button>
<button class="submit" style="display: block;">Yes</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我试过
browser.find_element_by_class_name("submit").click()
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
引发 exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementClickInterceptedException:消息:元素在点 (788,636.5) 处不可点击,因为另一个元素遮住了它
你能告诉我应该如何进行吗?我正在使用火狐和蟒蛇
您可以用操作类替换单击事件
使用动作类:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element("Your Web Element").click().perform()
Run Code Online (Sandbox Code Playgroud)
根据您的问题和您共享的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()
Run Code Online (Sandbox Code Playgroud)
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15598 次 |
最近记录: |