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,020 points
9,201 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,420 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,110 points
1,086 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 in Selenium by kaloo
219 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 in Selenium by Abha
• 27,180 points
1,068 views
0 votes
2 answers
0 votes
1 answer

Installing Selenium Webdriver with Python package

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

answered May 8 in Selenium by Anvi
• 13,960 points
241 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,110 points
1,006 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,130 points
1,153 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,420 points
964 views