selenium Edge alert
时间: 2023-08-21 16:05:22 浏览: 172
回答: 要在Selenium中处理Edge浏览器的alert弹窗,你可以使用以下示例代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
# 创建Edge浏览器实例
driver = webdriver.Edge()
# 设置隐式等待时间
driver.implicitly_wait(5)
# 打开网页
driver.get('http://cdn1.python3.vip/files/selenium/test4.html')
# 点击触发alert弹窗的按钮
driver.find_element(By.ID, 'b3').click()
# 切换到alert弹窗
alert = driver.switch_to.alert
# 打印弹窗提示信息
print(alert.text)
# 输入信息并点击OK按钮提交
alert.send_keys('web自动化 - selenium')
alert.accept()
# 点击Cancel按钮取消
driver.find_element(By.ID, 'b3').click()
alert = driver.switch_to.alert
alert.dismiss()
这段代码演示了如何在Edge浏览器中处理alert弹窗。你可以根据自己的需求进行修改和扩展。\[1\]
#### 引用[.reference_title]
- *1* *2* *3* [Web自动化测试教程汇总|9.selenium 实战高级技巧](https://blog.csdn.net/zh6526157/article/details/122096960)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文