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

你。 提交于 2019-12-04 19:52:46

问题


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:


This works for chrome-

driver.execute_script("window.open('https://www.google.com');")


来源:https://stackoverflow.com/questions/35208342/how-to-open-new-tab-in-chrome-with-selenium-chromedriver-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!