Not able to open a new URL in a new tab in Selenium

0 votes

I want to open different tabs with different URLs using Selenium WebDriver & Python.

I used the below code but it is not working for me:

driver = webdriver.Chrome()
driver.get(url_1)
time.sleep(10)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL+'t')
url_2 = 'https://www.gmail.com'
driver.get(item_2)
May 21, 2018 in Selenium by Perry
• 17,090 points
10,261 views

1 answer to this question.

0 votes

There is a bug in ChromeDriver that does not allow "Ctrl + T" from working.

 But you can open a link in a new tab and then switch to new tab using switch_to.window()

Below is a sample code:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://www.gmail.com")

# To open a link in a new tab
actions = Action(driver)
find = driver.find_element_by_link_text('ABC')
actions.key_down(Keys.CONTROL).click(find).key_up(Keys.CONTROL).perform()

driver.switch_to.window(driver.window_handles[-1])
driver.get("https://stackoverflow.com")

With this, the driver.get() would be performed in a newly opened tab.

answered May 21, 2018 by Meci Matt
• 9,460 points

Related Questions In Selenium

0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
1,251 views
0 votes
2 answers

How to open a link in a new tab?

try this :- driver.findElement(By.linkText("Business")).sendKeys(Ke ...READ MORE

answered Jan 10, 2019 in Selenium by kaloo
254 views
0 votes
1 answer

How to open new tab in same browser and switch between them using Selenium?

Hi Mugdha, you can use following code ...READ MORE

answered May 24, 2019 in Selenium by Abha
• 27,760 points
2,377 views
0 votes
2 answers

How to open a new tab in existing browser window using Javascript Executor?

Hi Meenal, you can use executeScript() method ...READ MORE

answered Jul 22, 2019 in Selenium by Abha
• 27,760 points
1,217 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,010 points
404 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
1,557 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
1,493 views
0 votes
5 answers
0 votes
1 answer

Open new tab instead of a new window in Selenium WebDriver

The current version of Selenium do not ...READ MORE

answered Jun 22, 2018 in Selenium by Meci Matt
• 9,460 points
1,222 views