如何在python splinter中打开两个选项卡 [英] how to open two tabs in python splinter

查看:183
本文介绍了如何在python splinter中打开两个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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]

如何在python splinter中打开两个选项卡并更改选项卡?

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

推荐答案

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/')

这篇关于如何在python splinter中打开两个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆