1 """弹出窗口处理""" 2 # -*- coding:utf-8 -*- 3 4 from selenium import webdriver 5 6 driver = webdriver.Firefox() 7 8 driver.get('http://www.baidu.com') 9 10 print driver.current_window_handle #获取当前句柄 11 12 driver.find_element_by_id('kw').send_keys('51testing') 13 14 driver.find_element_by_id('su').click() 15 16 driver.find_element_by_xpath(".//*[@id='1']/tbody/tr/td/h3/a").click() 17 temp = driver.window_handles #获取所有窗口句柄 18 driver.switch_to_window(temp[-1]) 19 #print temp 20 #print type(temp) 21 22 print driver.title