mac webdriver java,在Mac上使用Selenium WebDriver在Firefox中打开新选项卡

I just installed Selenium Web Driver and tried it out. It works great. My use case can be describe as followed:

Start Firefox on a server with pseudo X server (Xvfb)

New Driver.Firefox() object

Open 10 tabs and load a webpage in each tab

Retrieve the html from all loaded pages

The only step that is not working is step 3. I can not find out how to open new tabs. I found this here on SO : How to open a new tab using Selenium WebDriver with Java? However, I tested this locally (i.e. with visible display) on my Mac for debugging purpose and I saw that the Firefox browser (which was opened when creating the driver object) does not open any tabs when doing as described on the SO thread. So I tried this here:

driver = webdriver.Firefox()

driver.get("https://stackoverflow.com/")

body = driver.find_element_by_tag_name("body")

body.send_keys(Keys.CONTROL + 't')

As I said, it does not work for me. So, how else is it possible to open tabs? I use Selenium 2.39 (pip install selenium) and Python 2.7.

解决方案

the key combination to open a new tab on OSX is Command+T, so you should use

body.send_keys(Keys.COMMAND + 't')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值