Selenium doesn't open new URLs in new tabs (Python and Chrome)


Sam H123

I want to open a lot of URLs in different tabs using Selenium WebDriver and Python.

I'm not sure what's wrong:

driver = webdriver.Chrome()
driver.get(url1)
time.sleep(5)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL+'t')
url2 = 'https://www.google.com'
driver.get(item2)

I looked up the tutorial and it seems to me that this code should do what I want. What actually happens is that the browser opens, url1 opens, a new tab opens, but url2 then loads in the original tab, not the new tab (even though the new tab appears to be active).

(I'm using Chrome because I can't load any URLs at all when using Firefox. Firefox can open, but can't get the requested URL. I've tried to find a solution, but to no avail.)

Is there any change I can make in the code to make the new URL open in a new tab?

thank you for your help!

ec

There is a bug in ChromeDriver that prevents ctrl/command+T from working:

What you can do, as a workaround, is to open a link in a new tab and then switch to a new window to use switch_to.window(). Working sample:

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

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

# open a link in a new window
actions = ActionChains(driver)
about = driver.find_element_by_link_text('About')
actions.key_down(Keys.CONTROL).click(about).key_up(Keys.CONTROL).perform()

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

Now the last action driver.get()will be performed in the newly opened tab.

Related


Selenium doesn't open new URLs in new tabs (Python and Chrome)

Sam H123 I want to open a lot of URLs in different tabs using Selenium WebDriver and Python. I'm not sure what's wrong: driver = webdriver.Chrome() driver.get(url1) time.sleep(5) driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL+'t') url2 = 'https

Opening new tabs in Firefox and Chrome with Selenium doesn't work

Barrio (j.barrio): I read a lot of options related to the way new windows are opened with Selenium. All the questions and answers are from years ago, maybe that's why they didn't work for me. That's why I want to ask this question again. My first approach is t

Opening new tabs in Firefox and Chrome with Selenium doesn't work

Barrio (j.barrio): I read a lot of options related to the way new windows are opened with Selenium. All the questions and answers are from years ago, maybe that's why they didn't work for me. That's why I want to ask this question again. My first approach is t

Opening new tabs in Firefox and Chrome with Selenium doesn't work

Barrio (j.barrio): I read a lot of options related to the way new windows are opened with Selenium. All the questions and answers are from years ago, maybe that's why they didn't work for me. That's why I want to ask this question again. My first approach is t

Opening new tabs in Firefox and Chrome with Selenium doesn't work

Barrio (j.barrio): I read a lot of options related to the way new windows are opened with Selenium. All the questions and answers are from years ago, maybe that's why they didn't work for me. That's why I want to ask this question again. My first approach is t

Opening new tabs in Firefox and Chrome with Selenium doesn't work

Barrio (j.barrio): I read a lot of options related to the way new windows are opened with Selenium. All the questions and answers are from years ago, maybe that's why they didn't work for me. That's why I want to ask this question again. My first approach is t

How to make Chrome open bookmarks and URLs in new tabs?

Bradley I mostly use Firefox at home and at work, but sometimes I use Chrome. I got Firefox to work the way I like it by having it open bookmarks in a new tab on left click, as well as open URLs in a new tab. I like it, though it can be annoying to open a URL

How to make Chrome open bookmarks and URLs in new tabs?

Bradley I mostly use Firefox at home and at work, but sometimes I use Chrome. I got Firefox to work the way I like it by having it open bookmarks in a new tab on left click, as well as open URLs in a new tab. I like it, though it can be annoying to open a URL

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

Selenium C# Open "New" tab CTRL+T doesn't work with CHROME

crush static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl("http://google.com"); IWebElement body = driver.FindElement(By.TagName("body")); body.SendKeys(Keys.Control + "t"); } This is the code I'm trying to

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open a list of URLs on a new tab in Selenium + Python?

salbugit Code snippet: import selenium from selenium import webdriver driver = webdriver.Chrome() urls =['fb.com','instgram.com' , 'youtube.com'] for url in urls: driver.get(url) driver.close() The problem is that it opens the new link on top of the prev

How to open and manage new tabs with Selenium

Maurício Oliveira I'm trying to open a new tab using the "https://www.gmail.com" URL, then select some info and go back to the home page, I'm using the CTRL+t command to open the new tab, however, how do I switch between the two pages ? Snippet of my code: dri