#从百度搜索51cto并转到51cto学院首页

from selenium import webdriver b = webdriver.Firefox() b.get("http://baidu.com") ele = b.find_element_by_id("kw") ele.send_keys("51cto") ele.click() b.find_element_by_partial_link_text("IT系统培训领导者").click()

b.window_handles b.current_window_handle b.switch_to_window(b.window_handles[1])

b.current_windows_handle #显示当前句柄,此处指当前所在的窗口 b.window_handles #列出所有的句柄,此处指所有打开的浏览器窗口 b.switch_to_window #切换句柄,此处指切换窗口 b.current_url #显示当前句柄链接

b.switch_to_window(b.window_handles[1]) #切换到51cto窗口 b.switch_to_window(b.window_handles[0]) #切换到百度搜索结果窗口