'''
driver.switch_to.window() # 切换到指定的窗口对象中
driver.switch_to.frame() # 切换到指定的iframe
driver.switch_to.alert() # 切换到alert
driver.switch_to.default_content() # 切换到之前的页面中
driver.switch_to.parent_frame() # 切换到它爹的iframe
'''
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url='https://www.baidu.com')
driver.find_element_by_id('kw').send_keys('听雨危楼')
time.sleep(1)
driver.find_element_by_id('su').click()
time.sleep(2)
driver.find_element_by_link_text('听雨危楼 - 博客园').click()
time.sleep(2)
handles = driver.window_handles
print(handles)
time.sleep(2)
driver.switch_to.window(handles[0])
time.sleep(2)
driver.switch_to.window(handles[1])
time.sleep(3)
driver.quit()