1 # -*- coding:utf-8 -*- 2 """ 3 window.alert 处理 4 """ 5 6 from selenium import webdriver 7 8 driver = webdriver.Firefox() 9 driver.get(r'F:电子书seleniumSelenium Testing Tools Cookbook(中文)demoalert.html') 10 driver.find_element_by_id('alert').click() 11 12 #获取弹出窗口 13 alertBox = driver.switch_to_alert() 14 #获取弹出窗口中的文字 15 print alertBox.text 16 #确定 17 alertBox.accept()