how to open two tabs in python splinter

1.4k views Asked by At
from splinter import Browser

with Browser() as browser:
      browser.visit('https://google.com/')
      browser.visit('http://www.bing.com/')

      browser.windows[0]
      browser.windows[1]

How to open two tabs in python splinter and change tab?

1

There are 1 answers

2
Maks Skorokhod On
import time

from splinter import Browser
from selenium.webdriver.common.keys import Keys


with Browser() as browser:

    # visit fst url
    browser.visit('https://google.com/')
    # open new tab
    browser.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
    # visit second url
    browser.visit('https://www.bing.com/')

    # switching between tabs
    browser.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
    time.sleep(1)

    browser.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.SHIFT + Keys.TAB)
    time.sleep(1)

    browser.driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)

    # visit third url in fst tab
    browser.visit('https://stackoverflow.com/')