通过识别标题处理弹出窗口
1 # -*- coding:utf-8 -*- 2 """ 3 通过标题识别处理弹出窗口 4 """ 5 from selenium import webdriver 6 7 driver = webdriver.Firefox() 8 driver.get(r'F:\电子书\selenium\Selenium Testing Tools Cookbook(中文)\demo\window.html') 9 10 #获得父窗口句柄 11 parentWindowId = driver.current_window_handle 12 13 driver.find_element_by_id('helpbutton2').click() 14 15 #获取所有窗口的句柄 16 allWindowsId = driver.window_handles 17 18 for windowId in allWindowsId: 19 driver.switch_to_window(windowId) 20 if driver.title == 'PopUpWindow': 21 #driver.switch_to_window(windowId) 22 break 23 print driver.title 24 assert 'PopUpWindow', driver.find_element_by_tag_name('p').text