For those who might not know selenium is a library in many languages to work with browsers. In this specific case, I'm trying to connect in python script on the browser that the user lunches and can save all the running tabs. There are many things that I'm facing so I separated them into 3 problems. I hope they will be understandable. The main goal is to be able to connect to the browser without debug options.
Example
This is a script that should be able to connect to the browser that was launched with debug options in the command prompt. As I provide later I'm no longer able to connect to the remote browser at 127.0.0.1:9222." I've tried searching for a solution, but I haven't found one that works.
Launching browser in with debug port
"c:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=9222
Python script
from selenium import webdriver
from selenium.webdriver.edge.options import Options
edge_options = Options()
edge_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222')
driver = webdriver.Edge(options=edge_options)
driver.get(youtube.com)
printf(driver.title)
1. problem
For some reason, my code can no longer connect to the browser launched by the command mentioned. This is an error message Im facing.
part of the error message
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to microsoft edge at 127.0.0.1:9222 **from chrome not reachable **
full error message
Traceback (most recent call last):
File "C:\Users\user\OneDrive\Plocha\záložky\msedge - running\Try 18.py", line 7, in <module>
driver = webdriver.Edge(options=edge_options)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\edge\webdriver.py", line 73, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to microsoft edge at 127.0.0.1:9222
from chrome not reachable
Stacktrace:
Backtrace:
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF72EE616C2+15186]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EDFA212+827554]
(No symbol) [0x00007FF72EABEBF3]
(No symbol) [0x00007FF72EAAEC8A]
(No symbol) [0x00007FF72EAF013D]
(No symbol) [0x00007FF72EAE5D4A]
(No symbol) [0x00007FF72EB29C56]
(No symbol) [0x00007FF72EB21D23]
(No symbol) [0x00007FF72EAF3B80]
(No symbol) [0x00007FF72EAF2B0E]
(No symbol) [0x00007FF72EAF4344]
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF72ECDC3B0+182752]
(No symbol) [0x00007FF72EBB0095]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72ED3A6EA+42362]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72ED3D425+53941]
Microsoft::Applications::Events::ILogManager::DispatchEventBroadcast [0x00007FF72F058AB3+1456595]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE0276A+861690]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE07854+882404]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE079AC+882748]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE1097E+919566]
BaseThreadInitThunk [0x00007FF8D3C726BD+29]
RtlUserThreadStart [0x00007FF8D5A6DFB8+40]
What have I tried? There are many tutorials on using python and chrome, but not many are for an edge. Here are some samples of things I've tried:
https://www.youtube.com/watch?v=Zrx8FSEo9lk
https://www.youtube.com/watch?v=FGaU0OgtbNk&t=181s
https://www.youtube.com/watch?v=pZdMsLKAjs4&t=271s
https://bugs.chromium.org/p/chromedriver/issues/detail?id=710#c3
https://www.geeksforgeeks.org/automated-browser-testing-with-edge-and-selenium-in-python/
https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session
2. problem
My goal is to be able to connect to the browser that didn't start with debug port. Is there a way around the debug options?
What have I tried? Switching the localhost address with the IP address of processes named "msedge.exe". But it got the same error as mentioned.
3. problem
I'm wondering if there's a way to switch between these windows without having to repeatedly reconnect to each one. Is there a method or tool available that would allow me to easily navigate between these separate windows within the application, or do I have no choice but to reconnect each time? Any advice or suggestions would be greatly appreciated. Multiple windows of the browser
Please be patient, thanks for your help.