0

I open a second tab with the command indicated below. With which command do I open a new link using the same tab?

driver.execute_script("window.open('www.example');")

lolino
  • 97
  • 1
  • 8
  • [Stackoverflow answer](https://stackoverflow.com/questions/41086773/selenium-webdriver-python-reload-html-without-refreshing-the-page)This link will help you to resolve this – Justin Lambert Mar 19 '21 at 10:07
  • mmm sorry, I don't understand. I would like to open a new link `(driver.execute_script ("window.open ('www.example2');") ` from the same tab previously opened with `(driver.execute_script("window.open('www.example');")` – lolino Mar 19 '21 at 10:19

1 Answers1

0

Open a new tab as here and then verify than the correct link is opened How to open a new tab using Selenium WebDriver or here Open web in new tab Selenium + Python

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

driver = webdriver.Firefox()
driver.get("http://stackoverflow.com/")

body = driver.find_element_by_tag_name("body")
body.send_keys(Keys.CONTROL + 't')

driver.close()

For asserting use:

assert driver.title == "Expected page title"
vitaliis
  • 4,082
  • 5
  • 18
  • 40
  • Thank you very much for the guide, but I would like to open a new link in the same current tab, as if in the current open tab I paste a new link from the address bar. I hope I was clear – lolino Mar 19 '21 at 22:06
  • If you want to open a link in the same tab, why don't you just use: driver.get("https://somesite.com") ? – vitaliis Mar 20 '21 at 01:00
  • because I have to open it in the same tab. the command driver.get, at least to me, only refreshes the first tab still open. I need to do it in the second tab – lolino Mar 20 '21 at 11:01