1

i'm using this code to open edge with the defaut profile settings:

from msedge.selenium_tools import Edge, EdgeOptions
edge_options = EdgeOptions()
edge_options.use_chromium = True    
edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default")   
edge_options.add_argument("profile-directory=Profile 1")
edge_options.binary_location = r"C:\\Users\\PopA2\\Downloads\\edgedriver_win64 (1)\\msedgedriver.exe"
driver = Edge(options = edge_options, executable_path = "C:\\Users\\PopA2\\Downloads\\edgedriver_win64 (1)\\msedgedriver.exe")
driver.get('https://google.com')
driver.quit()

but i am getting this error:

PS C:\Users\PopA2> & "C:/Program Files/Python37/python.exe" "c:/Users/PopA2/OneDrive/Desktop/test de pe net.py" Traceback (most recent call last): File "c:/Users/PopA2/OneDrive Group/Desktop/test de pe net.py", line 13, in driver = Edge(options = edge_options, executable_path = "C:\Users\PopA2\Downloads\edgedriver_win64 (1)\msedgedriver.exe") File "C:\Program Files\Python37\lib\site-packages\msedge\selenium_tools\webdriver.py", line 108, in init desired_capabilities=desired_capabilities) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Program Files\Python37\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: MSEdge failed to start: was killed. (unknown error: DevToolsActivePort file doesn't exist) (The process started from msedge location C:\Users\PopA2\Downloads\edgedriver_win64 (1)\msedgedriver.exe is no longer running, so MSEdgeDriver is assuming that MSEdge has crashed.)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I've seen this issue before: https://stackoverflow.com/questions/69770506/webdriverexception-unknown-error-msedge-failed-to-start-was-killed. And this was the solution: https://stackoverflow.com/a/69848796 – Michael Mintz Jan 14 '22 at 17:37
  • How about the issue? Is [my answer below](https://stackoverflow.com/questions/70709117/python-selenium-opening-edge-with-default-user-profile/70738711#70738711) helpful to deal with the issue? I am glad to help if you have any other questions. – Yu Zhou Jan 28 '22 at 07:29

2 Answers2

0

Seems you were close. You need to remove the Default sub-directory from the path mentioned through user-data-dir.

Effectively your line of code will be:

edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Are you running the program under LocalSystem account? If so, the issue is the same as which mentioned in the comment and this thread.

I suggest that you can provide feedback about this issue to Edge team by pressing Alt+Shift+I in Edge. For now, the only workaround is not to run Edge under LocalSystem account.

Besides, if you want to run Edge with default profile, you can use the below line of code and there's no need to specify profile-directory. You can also add --remote-debugging-port argument to fix the issue:

edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data")
edge_options.add_argument("--remote-debugging-port=9222") 
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22