Open web in new tab Selenium + Python

后端 未结 11 2212
别跟我提以往
别跟我提以往 2020-11-22 01:15

So I am trying to open websites on new tabs inside my WebDriver. I want to do this, because opening a new WebDriver for each website takes about 3.5secs using PhantomJS, I w

11条回答
  •  醉酒成梦
    2020-11-22 01:45

    The other solutions do not work for chrome driver v83.

    Instead, it works as follows, suppose there is only 1 opening tab:

    driver.execute_script("window.open('');")
    driver.switch_to.window(driver.window_handles[1])
    driver.get("https://www.example.com")
    

    If there are already more than 1 opening tabs, you should first get the index of the last newly-created tab and switch to the tab before calling the url (Credit to tylerl) :

    driver.execute_script("window.open('');")
    driver.switch_to.window(len(driver.window_handles)-1)
    driver.get("https://www.example.com")
    

提交回复
热议问题