1

I want to get the URL of the currently open website in Chrome:

from selenium import webdriver

driver = webdriver.Chrome()

print(driver.current_url)

However this only opens a new Chrome window with "data:," as its url. What do I have to do to get for example "Youtube.com" when I have youtube open

Connor Kolan
  • 81
  • 2
  • 9

1 Answers1

0

Okay, but you actually forgot to open youtube.com URL:


driver = webdriver.Chrome()

driver.get('https://www.youtube.com/') # << Ask driver to open site of interest

print(driver.current_url)
Yevhen B
  • 306
  • 1
  • 4
  • I think I wrote it a bit misleading. What I wanted to ask is how to get the url of an already open tab in browser. But I found out that this is impossible with selenium. – Connor Kolan Mar 13 '21 at 21:58
  • In general it is agains the spirit of Selenium, but you still could try [this] (https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session) – Yevhen B Mar 13 '21 at 22:49