2

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

2
  • You can't access Browser windows not opened via Selenium. You would need to build Chrome extension for such cases Commented Mar 12, 2021 at 9:29
  • where is the line to load youtube?
    – Wonka
    Commented Mar 12, 2021 at 10:42

1 Answer 1

1

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)
2
  • 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. Commented Mar 13, 2021 at 21:58
  • In general it is agains the spirit of Selenium, but you still could try [this] (stackoverflow.com/questions/8344776/…)
    – Yevhen B
    Commented Mar 13, 2021 at 22:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.