Python selenium+webdriver 解決頁面點擊跳轉之后的獲取當前頁面元素問題


在頁面跳轉之前用:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM