from selenium import webdriver
import time
# 浏览器多窗口处理,出现多个浏览亲戚
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.maximize_window()
driver.implicitly_wait(30)
#首先获取当前窗口的句柄,句柄:一个页面的唯一标识符
nowhandle=driver.current_window_handle
print(nowhandle)
#获取所有窗口句柄
driver.find_element_by_link_text('京公网安备11000002000001号').click()
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/input').send_keys('切句柄')
# driver.quit()
driver.switch_to.window(nowhandle)
driver.find_element_by_name('wd').send_keys('句柄')
driver.find_element_by_id('su').click()