web自动化之alert弹窗操作

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

driver = webdriver.Chrome()

driver.get("url")
# 判断alert是否出现
WebDriverWait(driver,20).until(EC.alert_is_present())
# 进入alert弹窗
alert = driver.switch_to.alert
# 获取alert弹窗的文本
alert.text
# 输入文本
alert.send_keys("随便")
# 接受弹窗
alert.accept()
# 取消弹窗
alert.dismiss()

 

转载于:https://www.cnblogs.com/666666pingzi/p/10568864.html

你可能感兴趣的:(web自动化之alert弹窗操作)