python 处理ALERT https://www.cnblogs.com/fengyiru6369/p/7229883.html

  https://www.cnblogs.com/fengyiru6369/p/7229883.html

import time from selenium import webdriver import win32api import win32con from time import sleep driver = webdriver.Chrome() url = r'file:///C:\Users\TYu3\PycharmProjects\pythonProject\test.html' driver.get(url) try: js = 'window.confirm = function() {}; window.alert = function() {};' driver.execute_script(js) except: pass time.sleep(2) js = 'window.confirm = function() {}; window.alert = function() {};' driver.execute_script(js) # driver.find_element_by_xpath('/html/body/div/input[2]').click() # '''获取alert对话框''' # alert = driver.switch_to_alert() # '''添加等待时间''' # time.sleep(2) # '''获取警告对话框的内容''' # print (alert.text) #打印警告对话框内容 # alert.accept() #alert对话框属于警告对话框,我们这里只能接受弹窗 # '''添加等待时间''' time.sleep(211) driver.quit()

  

posted @ 2021-04-19 15:43  kaxio  阅读(116)  评论(0)    收藏  举报