标签:handle 句柄 time driver style and quit 入门 窗口切换
窗口切换:
#coding=utf-8 #切换窗口 from selenium import webdriver import time dr = webdriver.Firefox() dr.get("http://www.baidu.com") dr.find_element_by_link_text("登录").click() time.sleep(1) dr.find_element_by_link_text("立即注册").click() origin_handle = dr.current_window_handle #保存当前窗口 print(‘当前窗口title:‘,dr.title) handles = dr.window_handles #获取所有窗口 for handle in handles: if handle != origin_handle: dr.switch_to_window(handle) time.sleep(1) print(‘当前窗口title:‘,dr.title) #切换回原窗口 dr.switch_to_window(origin_handle) print(‘当前窗口title:‘,dr.title) time.sleep(1) dr.quit()
标签:handle 句柄 time driver style and quit 入门 窗口切换
原文地址:https://www.cnblogs.com/dinghanhua/p/9746520.html