在浏览器中新开一个tab

本文介绍如selenium方法打开一个新的 ayx tab,我爱游戏们知道在浏览器里,我们按住 ctrl+ t 就可以新打开一个tab。所以我们学习如何利用webdriver中send_key 的方法去触发ctrl+t的效果。我们利用火狐浏览器来演示。
相关代码如下:
主要是爱游戏官网调用了keys模块下相关方法,可以通过这个方法,输入任何一个键盘上支持的字符或者快捷键。
# coding=utf-8
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(6)
driver.get("https://www.baidu.com/")
time.sleep(1)
ele = driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't') # 触发ctrl + t

time.sleep(1)
发表评论
评论列表
This is my third time ordering from this seller, and they never disappoint. Fast shipping and great customer service. Very happy with my purchase.
Absolutely love this product! It's exactly what I needed and works perfectly. This is my third time ordering from this seller, and they never disappoi
Exceeded my expectations in quality and performance. Highly recommend! Fast shipping and great customer service. Very happy with my purchase.