from selenium import webdriverimport timed = webdriver.Firefox()d.get("http://www.baidu.com")d.find_element_by_id("kw").clear()d.find_element_by_id("kw").send_keys("周杰伦")d.find_element_by_id("su").click()time.sleep(1)d.find_element_by_partial_link_text("百度百科").click()#查看Windows属性:print(d.window_handles)#查看Windows句柄:print(d.current_window_handle)d = webdriver.Firefox()print(d.window_handles)print(d.current_window_handle)#按索引切换窗口:d.switch_to_window(d.window_handles[1])
来源:https://www.cnblogs.com/zhang-da/p/12057838.html