Selenium won't open a new URL in a new tab (Python & Chrome)

后端 未结 4 1746
日久生厌
日久生厌 2020-11-27 17:03

I want to open quite a few URLs in different tabs using Selenium WebDriver & Python.

I am not sure what is going wrong:

driver = webdriver.Chrome         


        
4条回答
  •  星月不相逢
    2020-11-27 18:03

    Here is a simple way, platform independent:

    Code:

    driver.execute_script("window.open('http://google.com', 'new_window')")
    

    Switching back to the original tab:

    Code:

    driver.switch_to_window(driver.window_handles[0])
    

    Checking the current title to be sure you are on the right page:

    Code:

    driver.title
    

    For everything else, have fun!

提交回复
热议问题