Lee Lee - 1 year ago 155
Python Question

python-selenium and ChromeDriver: Can't open tab to control it

I'm unable to open a new tab - or even click on a link and open it on a new tab - with Python 2.7.1, Selenium 2.53.0, ChromeDriver 2.22 and Google Chrome 51.0 on Mac OS X.

import selenium.webdriver as webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep

driver = webdriver.Chrome('/path/to/chromedriver')

driver.find_element_by_id('signin-email').send_keys(Keys.COMMAND + 't')

It opens the URL, but it doesn't open a new tab.

I've also tested opening a new tab with ActionChains, but no success.

The only method to open new tab that works is with JavaScript through
, but I'm not able to control the new tab in that case.
doesn't work.

Answer Source

You should try as below :-

driver.find_element_by_id('signin-email').send_keys(Keys.COMMAND + Keys.RETURN);

Hope it will help you..:)