Open web in new tab Selenium + Python

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

    tabs = {}
    
    def new_tab():
        global browser
        hpos = browser.window_handles.index(browser.current_window_handle)
        browser.execute_script("window.open('');")
        browser.switch_to.window(browser.window_handles[hpos + 1])
        return(browser.current_window_handle)
        
    def switch_tab(name):
        global tabs
        global browser
        if not name in tabs.keys():
            tabs[name] = {'window_handle': new_tab(), 'url': url+name}
            browser.get(tabs[name]['url'])
        else:
            browser.switch_to.window(tabs[name]['window_handle'])
    

提交回复
热议问题