当前位置:网站首页>Slenium tips: how to handle some dialog boxes that may appear on Web pages

Slenium tips: how to handle some dialog boxes that may appear on Web pages

2022-06-25 20:20:00 A novice Test Engineer

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

 Insert it here import time
from selenium import webdriver
driver=webdriver.Chrome()
driver.implicitly_wait(10)
driver.get('file:///D:/autoUI_selenium/lesson06/al.html')
# Trigger alert Dialog box 
driver.find_element_by_css_selector('#b1').click()
time.sleep(2)
# Switch to alert The above object 
#driver.switch_to.window()# Switch windows 
#driver.switch_to.frame()# Switch to frame
al=driver.switch_to.alert
al.accept()# Call the confirmation method to confirm 
# Trigger comfirm Dialog box 
driver.find_element_by_css_selector('#b2').click()
time.sleep(2)
al1=driver.switch_to.alert
#al1.accept()# Call the confirmation method to confirm 
al1.dismiss()# Call the cancel method to cancel 
# Trigger promt Dialog box 
driver.find_element_by_css_selector('#b3').click()
time.sleep(2)
al2=driver.switch_to.alert
al2.send_keys('123')# The input character 
al2.accept() Into the code slice 
原网站

版权声明
本文为[A novice Test Engineer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190501341029.html