-*-coding:utf-8-*-
#导入webdriver模块
from selenium import webdriver
#导入time模块
import time
#打开谷歌浏览器
driver = webdriver.Chrome()
#打开网址
driver.get('http://news.baidu.com/')
time.sleep(5)
#获取当前窗口句柄
h = driver.current_window_handle
print(h)
time.sleep(5)
driver.find_element_by_link_text("全票当选为国家主席、*军委主席").click()
time.sleep(5)
#获取所有窗口句柄
a = driver.window_handles
print(a)
#切换句柄方法一
# for i in a:
# if i != h:
# driver.switch_to.window(i)
# print(driver.title)
#切换句柄方法二
driver.switch_to.window(a[1])
print(driver.title)