1 # -*- coding:utf-8 -*- 2 from selenium import webdriver 3 from selenium.webdriver.common.action_chains import ActionChains 4 from selenium.webdriver.support.ui import WebDriverWait 5 6 import time 7 8 driver = webdriver.Firefox(executable_path='/Users/huiliang/Downloads/geckodriver') 9 driver.get("http://www.baidu.com/") 10 #driver.implicitly_wait(10) 11 print 'baidu:' + driver.current_window_handle 12 13 driver.find_element_by_id('kw').clear() 14 driver.find_element_by_id('kw').send_keys(u'百度网盘') 15 driver.find_element_by_id('su').click() 16 driver.implicitly_wait(10) 17 18 driver.find_element_by_partial_link_text(u'享你所想').click() 19 print 'baiduwangpan:' + driver.current_window_handle 20 21 print driver.window_handles 22 23 ''' 24 每一个浏览器都有自己的句柄,也就是current_window_handle 25 查看所有浏览器的句柄 window_handles 是以数组形式出现 26 切换语句 driver.switch_to.window(window_handles[2]) 27 ''' 28 29 time.sleep(10) 30 driver.quit()