0

I want to create a qrcode that points to a web page that is currently open in my Edge browser, the qrcode creation works fine but I'm struggling to get the URL.

Reading online shows that Selenium is useful, however this creates a new session and just returns Data;\ which is not useful.

Is there a way that I can just grab the URL from the current Edge session?

Many thanks,

lolamnma
  • 43
  • 1
  • 6
  • You can't connect to an existing browser session using Selenium unless you launch the browser with remote debugging like what described in [this article](https://cosmocode.io/how-to-connect-selenium-to-an-existing-browser-that-was-opened-manually/). But I think you're opening the browser directly, so I think there's no way to achieve what you want. You can also refer to [this accepted answer](https://stackoverflow.com/questions/47861813/how-can-i-reconnect-to-the-browser-opened-by-webdriver-with-selenium/47862867#47862867). – Yu Zhou Feb 15 '22 at 06:49

1 Answers1

1

That should be simply:

from selenium import webdriver
  

driver = webdriver.EdgeDriver()
driver.get(url)  # navigating to url
  
get_url = driver.current_url  # getting current url
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • Sorry, I'm just a little confused since I don't want to type the URL into selenium to get the same URL that I just typed in. I want it to be able to get the URL from my other browser. – lolamnma Feb 14 '22 at 12:00
  • Sorry, I now edited Chrome to Edge. Let me explain: `driver.get("www.some-url.com")` will navigate to the URL provided (www.some-url.com). `driver.current_url` will return the current URL at the time that you called it. – Mate Mrše Feb 14 '22 at 12:27
  • Please bear with me since I'm struggling to understand. What you have suggested will create a new session, browse to the url that I provided, then get the url that the browser ends on. My problem is, it creates a new session and does not interact with the current Edge session that I already have open. The url I need is different depending on what the user selected in that original browser session. Is there a way for python, instead of creating a new session, to connect and grab the URL from the original session. – lolamnma Feb 14 '22 at 12:41
  • Oh, now I see. In that case, see if this is useful: https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session – Mate Mrše Feb 14 '22 at 12:44