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? 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)
Sign up to request clarification or add additional context in comments.

2 Comments

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.
In general it is agains the spirit of Selenium, but you still could try [this] (stackoverflow.com/questions/8344776/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.