How to open new tab in Chrome with Selenium-chrome

2019-03-27 17:07发布

Is there anybody who used ChromeDriver to open new tabs in Chrome?

With this code I can open my index.html in Chrome:

driver = webdriver.Chrome("/usr/bin/chromedriver")
driver.get("localhost:3000")

And then I want to open localhost:3000/cloudPeer.html in a new tab:

driver.find_element_by_tag_name("body").send_keys(Keys.CONTROL + 't')
driver.get("localhost:3000/cloudPeer.html")

This works well in Firefox, but in Chrome, it can't open a new tab, it just refresh the first page, and open the new page, the first page is now lost.
I want to open these two pages at the same time and do some communication tests between them.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-03-27 17:50

This works for chrome-

driver.execute_script("window.open('https://www.google.com');")
查看更多
登录 后发表回答