Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Selenium-5 multi-window switching

Shulou Source: shulou.com Published: 2022-06-03 06:37:27 11月23日 Update

# search 51cto from Baidu and go to the home page of 51cto College

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 system training leaders"). Click ()

B.window_handles

B.current_window_handle

B.switch_to_window (b.window_handles [1])

B.current_windows_handle # displays the current handle, in this case, the window in which it is located

B.window_handles # lists all handles, in this case, all open browser windows

B.switch_to_window # switch handle, in this case, toggle window

B.current_url # shows the current handle link

B.switch_to_window (b.window_handles [1]) # switch to 51cto window

B.switch_to_window (b.window_handles [0]) # switch to Baidu search results window

Tags: Switch handle search academy location search results browser system results links leaders home page training browse Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB vpn macOS Linux