Open web in new tab Selenium + Python

后端 未结 11 2200
别跟我提以往
别跟我提以往 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:53

    Strangely, so many answers, and all of them are using surrogates like JS and keyboard shortcuts instead of just using a selenium feature:

    def newTab(driver, url="about:blank"):
        wnd = driver.execute(selenium.webdriver.common.action_chains.Command.NEW_WINDOW)
        handle = wnd["value"]["handle"]
        driver.switch_to.window(handle)
        driver.get(url) # changes the handle
        return driver.current_window_handle
    

提交回复
热议问题