Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium new tab in chrome browser by python webdriver

I am not being able to open a new tab in chrome. My requirement is to open a new tab do some operation then close this new tab and come back to old tab. The below python code worked in Firefox but not working in Chrome. Could anyone please help me?

ActionChains(driver).key_down(Keys.CONTROL,body).send_keys('t').key_up(Keys.CONTROL).perform()
like image 652
Subham Sen Avatar asked Jul 22 '15 09:07

Subham Sen


1 Answers

Guess this will be helpful:

from selenium import webdriver
driver = webdriver.Chrome()
driver.execute_script("window.open('','_blank');")

This piece of code should start new Chrome browser session and open blank page in new tab

Use driver.execute_script("window.open('URL');") to open new tab with required URL

like image 69
Andersson Avatar answered Sep 29 '22 18:09

Andersson