python selenium open link in new tab and continue session in new tab


Ash

When selenium clicks the link and opens a new tab, I lose my current session. I don't know how to continue a session in a new tab on yahoo.com.

driver.get("https://in.yahoo.com")
search_field = driver.find_element_by_id('header-search-input')
search_field.clear()
search_field.send_keys('guru99')
search_field.submit()
elements =driver.find_element_by_xpath('//a[contains(@href, "https://www.guru99.com")]')
elements.click()
driver.find_element_by_link_text("What is Python?")
time.sleep(20)
driver.close()
Alderwin

You can open search results in the same tab:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://in.yahoo.com")
search_field = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, 'header-search-input')))
search_field.clear()
search_field.send_keys('guru99')
search_field.submit()
el = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a[contains(@href, "https://www.guru99.com")]')))
url = el.get_attribute('href')
driver.get(url)
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//*[@title="Python"]'))).click()
driver.close()

Related


How to open link in new tab using python and selenium

User 3820991 I want to open links found on a website in a new tab. I tried to open a new tab and passed the link URL to the motorists suggested here however, the new tab does not open at all. (There are some other suggestions on how to open new tabs, but none

How to open link in new tab using python and selenium

User 3820991 I want to open links found on a website in a new tab. I tried to open a new tab and passed the link URL to the motorists suggested here however, the new tab does not open at all. (There are some other suggestions on how to open new tabs, but none

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and need to validate the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and conti

Open link in new tab

no mice here I need to open a link <a>in a new tab/window 's tab, do something there and then close it. html code: <body> <a id="uniqueid" href="somelink">I need to open this in a new tab</a> </body> python code: from selenium import webdriver driver = w

Selenium 2: open link in new tab and close tab

Alps: I want to be able to open links in new tabs in Selenium 2. I also want to close the tab after I finish interacting with the page. How is this possible if I have WebElementa <a>tag? I'm using Selenium 2's Java API with the Firefox driver running on Firefo

Selenium 2: open link in new tab and close tab

Alps: I want to be able to open links in new tabs in Selenium 2. I also want to close the tab after I finish interacting with the page. How is this possible if I have WebElementa <a>tag? I'm using Selenium 2's Java API with the Firefox driver running on Firefo

Selenium 2: open link in new tab and close tab

Alps: I want to be able to open links in new tabs in Selenium 2. I also want to close the tab after I finish interacting with the page. How is this possible if I have WebElementa <a>tag? I'm using Selenium 2's Java API with the Firefox driver running on Firefo

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

Open Web Selenium + Python in a new tab

Robert Hunt So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python scrip

Python + Selenium WebDriver: open URL in new tab

Luke Van Zweiden I have a text document with a URL per line. I want each URL to open in a new tab. Here is what I have so far: tabs = 0 f = open('links.txt', 'r', encoding='utf-8') for line in f: url = line driver.execute_script("window.open(url, 'new_

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Open Web Selenium + Python in a new tab

Robert W. Hunter: So I am trying to open the website on a new tab inside WebDriver. I want to do this because it takes about 3.5 seconds to open a new WebDriver for each website using PhantomJS, so I want to improve the speed... I'm using a multiprocess python

How to open new tab using selenium python?

Good face I'm trying to make a program that can open multiple websites, but I can't press control-t. I tried multiple solutions but couldn't find one that worked. When I execute the keydown method, I get an error message webdriver has no attribute key_down Wh

Open element (url) in new tab in Python Selenium

ASP Goal: Need to open a webpage, find urls by class, and open each url in a new tab in chrome What I have tried: from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys driver = webdriver.Chro

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Python + Selenium WebDriver: open URL in new tab

Luke Van Zweiden I have a text document with a URL per line. I want each URL to open in a new tab. Here is what I have so far: tabs = 0 f = open('links.txt', 'r', encoding='utf-8') for line in f: url = line driver.execute_script("window.open(url, 'new_

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Send chords to open New Tab Selenium Python

Mick I have this super simple code that I want to run on ChromeDriver but it's not working. The Java equivalent works fine. I'd like to open a new tab, but any way of sending multiple keys would work just fine. driver.get("https://www.google.com") action = Act

Open link in new tab or window

Rene Is it possible to open a link a hrefin a new tab instead of the same tab ? <a href="http://your_url_here.html">Link</a> Nason You should add target="_blank"and in the anchor tag rel="noopener noreferrer". E.g: <a target="_blank" rel="noopener noreferrer"

pandoc: open link in new tab

singles According to this answer , it should be possible to use the following syntax [link](url){:target="_blank"} When used, links can be opened in a new tab pandoc. However, this option does not seem to be supported as it is not recognized when converting t