在頁面跳轉之前用: current_window = firefox_login.current_window_handle # 獲取當前窗口handle name 跳轉之后先獲取到頁面的全部handle,在進行動作: all_window=firefox_login.window_handles for window in all_window: if window != current_window: firefox_logi EXAMPLE: firefox_login=webdriver.Firefox() firefox_login.get('') #填入URL firefox_login.find_element_by_xpath('').clear() firefox_login.find_element_by_xpath('').send_keys() #'填入賬號' firefox_login.find_element_by_xpath('').clear() firefox_login.find_element_by_xpath('').send_keys() #'填入密碼' current_window = firefox_login.current_window_handle # 獲取當前窗口handle name firefox_login.find_element_by_xpath('//*[@id="loginbtn"]').click() all_window=firefox_login.window_handles for window in all_window: if window != current_window: firefox_login.switch_to.window(window) current_window = firefox_login.current_window_handle # 獲取當前窗口handle name firefox_login.find_element_by_xpath('').click() n.switch_to.window(window) ———————————————— 版權聲明:本文為CSDN博主「White_Hou」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。 原文鏈接:https://blog.csdn.net/H_12306/java/article/details/81110428
重點在於:current_window_handle 和window_handles
在頁面跳轉之前用:
current_window = firefox_login.current_window_handle # 獲取當前窗口handle name
跳轉之后先獲取到頁面的全部handle,在進行動作:
all_window=firefox_login.window_handles
for window in all_window:
if window != current_window:
firefox_logi
EXAMPLE:
firefox_login=webdriver.Firefox()
firefox_login.get('') #填入URL
firefox_login.find_element_by_xpath('').clear()
firefox_login.find_element_by_xpath('').send_keys() #'填入賬號'
firefox_login.find_element_by_xpath('').clear()
firefox_login.find_element_by_xpath('').send_keys() #'填入密碼'
current_window = firefox_login.current_window_handle # 獲取當前窗口handle name
firefox_login.find_element_by_xpath('//*[@id="loginbtn"]').click()
all_window=firefox_login.window_handles
for window in all_window:
if window != current_window:
firefox_login.switch_to.window(window)
current_window = firefox_login.current_window_handle # 獲取當前窗口handle name
firefox_login.find_element_by_xpath('').click()
n.switch_to.window(window)
————————————————
版權聲明:本文為CSDN博主「White_Hou」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/H_12306/java/article/details/81110428