标签:图片 ext imp bsp handle port handles alt 返回
# 多窗口切换 # current_window_handle :获得当前窗口句柄 # window_handles :返回所有窗口的句柄到当前会话上 # switch_to_window : 用于切换到不同的窗口 from selenium import webdriver from time import sleep url = ‘https://www.baidu.com/‘ def win_swith(): driver = webdriver.Chrome() driver.implicitly_wait(10) driver.get(url) win1 = driver.current_window_handle driver.find_element_by_link_text(‘登录‘).click() sleep(3) driver.find_element_by_link_text(‘立即注册‘).click() sleep(5) winall = driver.window_handles driver.switch_to_window(win1) sleep(3) a1 = driver.current_url print(a1) driver.switch_to_window(winall[1]) sleep(3) a2 = driver.current_url print(a2) driver.switch_to_window(winall[0]) sleep(3) a3 = driver.current_url print(a3) sleep(3) driver.quit() if __name__ == ‘__main__‘: win_swith()
标签:图片 ext imp bsp handle port handles alt 返回
原文地址:https://www.cnblogs.com/biqiuqiu/p/10505883.html