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.

2
  • I know how it works in Java. Can you implement the same login in python and see that works? Please refer stackoverflow.com/questions/34829329/…. Also is it t (in single quote) in python? In java, it is t in (double quote) to open a tab. Commented Feb 4, 2016 at 21:11
  • 2
    Please do not open multiple tabs. Use multiple webdriver instances and open another window. It is much more stable. Commented Feb 4, 2016 at 22:11

1 Answer 1

29

This works for chrome-

driver.execute_script("window.open('https://www.google.com');")
Sign up to request clarification or add additional context in comments.

3 Comments

How to switch tabs?
Use driver.switch_to.window(driver.window_handles[-1]) to switch to the most recently opened tab.
How to get the page_source ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.