alert 窗口的类型:
警告框、确认框、对话框
操作 alert 窗口:
切换至 alert 窗口:driver.switch_to.alert
获取alert 窗口的值:alert.text
确定:alert.accept()
取消:alert.dismiss()
输入值:alert.send_keys("内容")
from selenium import webdriver标签:窗口,处理,text,driver,accept,alert,alert1 From: https://www.cnblogs.com/xianyumaixianyu/p/18278128
import time
driver = webdriver.Chrome()
driver.get("file:///C:/Users/Administrator/Desktop/alert.html")
driver.maximize_window()
def alert_demo_1():
# 警告框
alert1 = driver.find_element_by_id('bu1')
alert1.click()
# 切换至警告框
alert1 = driver.switch_to.alert
# 获取 alert 窗口的值
print(alert1.text)
# 点击确定
alert1.accept()