13

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.

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
Jialei Cheng
  • 141
  • 1
  • 2
  • 8
  • I know how it works in Java. Can you implement the same login in python and see that works? Please refer http://stackoverflow.com/questions/34829329/how-to-open-a-link-in-new-tab-chrome-using-selenium-webdriver/34831289#34831289. Also is it t (in single quote) in python? In java, it is t in (double quote) to open a tab. – Abdul Hameed Feb 04 '16 at 21:11
  • 2
    Please do not open multiple tabs. Use multiple webdriver instances and open another window. It is *much* more stable. – Nathan Merrill Feb 04 '16 at 22:11

1 Answers1

29

This works for chrome-

driver.execute_script("window.open('https://www.google.com');")
sidpat
  • 735
  • 10
  • 26