浏览器弹出框
1.定位元素,触发弹框
2.等待弹框出现
3.switch_to切换到浏览器弹出框,driver.switch_to.alert
4.Alert提供了一系列操作方法
dismiss():否;
accept():是;
text():获取弹框里的内容;
send_keys():往弹框里输入文本
from selenium.webdriver import Chrome
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = Chrome()
driver.get("XXX_url_XXX")
# 点击页面元素,触发弹框
driver.find_element_by_id("xxx").click()
# 等待弹框出现
wait = WebDriverWait(driver,20)
wait.until(EC.alert_is_present())
# 从html页面切换到Alert弹框
alert = driver.switch_to.alert()
# 获取Alert文本内容
text = alert.text
# 接受,选择okay
alert.accept()
# 退出浏览器
driver.quit()