Selenium- alert -confirm -prompt三种弹窗
程序员文章站
2022-04-08 21:41:35
...
#定位alert弹窗的属性 并点击
#调用switch_to_alert.accept()
#定位confim弹窗
调用switch_to.alert.accept()
#点击取消
switch_to.alert.dismiss()
#定位prompt弹窗 输入内容吧并确定
调用 switch_to.alert.send_kyes("")
#点击确定
switche_to.alert.accept()
代码如下
from selenium import webdriver
import time
driver = webdriver.Chrome()
#alert弹窗
driver.get("http://sahitest.com/demo/alertTest.htm")
driver.find_element_by_name("b1").click()
time.sleep(3)
driver.switch_to.alert.accept()
time.sleep(3)
#confim弹窗 确定 取消
driver.get("http://sahitest.com/demo/confirmTest.htm")
driver.find_element_by_name("b1").click()
time.sleep(3)
driver.switch_to.alert.accept()
time.sleep(3)
driver.find_element_by_name("b1").click()
time.sleep(3)
driver.switch_to.alert.dismiss()
time.sleep(3)
#promot 弹窗 输入内容并 确定或取消
driver.get("http://sahitest.com/demo/promptTest.htm")
driver.find_element_by_name("b1").click()
time.sleep(3)
driver.switch_to.alert.send_keys("1123")
time.sleep(3)
driver.switch_to.alert.accept()
time.sleep(3)
driver.quit()
推荐阅读
-
Javascript中弹窗confirm与prompt的区别
-
Javascript中弹窗confirm与prompt的区别
-
JavaScript的三种弹出提示框(alert、confirm、prompt)
-
JavaScript中常用的3种弹出提示框(alert、confirm、prompt)
-
JavaScript BOM:Window对象弹出方法、alert、confirm、prompt
-
12.12 window对象: alert confirm和prompt
-
window对象方法(alert-confirm-prompt)
-
JS中confirm,alert,prompt函数区别分析_javascript技巧
-
javascript中常见的3种信息提示框(alert,prompt,confirm)_javascript技巧
-
JavaScript的三种弹出提示框(alert、confirm、prompt)