Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open new tab in Chrome with Selenium-chromeDriver in Python

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.

like image 786
Jialei Cheng Avatar asked Feb 04 '16 18:02

Jialei Cheng


Video Answer


1 Answers

This works for chrome-

driver.execute_script("window.open('https://www.google.com');")
like image 191
sidpat Avatar answered Oct 06 '22 08:10

sidpat