I am trying to open the default profile using selenium in python using the following code :
from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.keys import Keys
options = EdgeOptions()
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
options.use_chromium = True
options.add_argument("user-data-dir=C:\\Users\\UserName\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("profile-directory=Default")
options.add_argument("--start-maximized")
options.add_argument("--remote-debugging-port=9222")
driver = Edge(options = options,executable_path=r'C:\Users\UserName\Desktop\Programs\msedgedriver.exe')
driver.get ("https://www.google.com")
driver.close()
When I run the code, the default profile browser opens successfully but the driver closes automatically due to some error. The line to get www.google.com did not run.
The error message:
Warning (from warnings module):
File "C:\Users\UserName\Desktop\MS Credit automation\Test.py", line 12
driver = Edge(options = options,executable_path=r'C:\Users\UserName\Desktop\Programs\msedgedriver.exe')
DeprecationWarning: Selenium Tools for Microsoft Edge is deprecated. Please upgrade to Selenium 4 which has built-in support for Microsoft Edge (Chromium): https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/#upgrading-from-selenium-3
Traceback (most recent call last):
File "C:\Users\UserName\Desktop\Programs\Test.py", line 12, in <module>
driver = Edge(options = options,executable_path=r'C:\Users\UserName\Desktop\Programs\msedgedriver.exe')
File "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\msedge\selenium_tools\webdriver.py", line 107, in __init__
RemoteWebDriver.__init__(
File "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\UserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Microsoft Edge failed to start: exited normally.
(chrome not reachable)
(The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
I am using
- python 3.11.1
- edge 115.0.1901.188
- edge driver 115.0.1901.188
- windows 11
When I remove the code to direct the path to open the default profile, the code runs fine. But a new profile is created each time. The lines at question are :
options.add_argument("user-data-dir=C:\\Users\\UserName\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("profile-directory=Default")
I would like to know the problem or an alternative solution to the problem please.