I am a beginner to Selenium python. I have tried to invoke the Edge browser with an existing profile(Default) with the following code. But it is throwing the following exception as soon as the execution starts. Can someone please help me with this? Am I missing something?
edge_options = webdriver.EdgeOptions()
edge_options.add_argument("user-data-dir = C:/Users/XYZ/AppData/Local/Microsoft/Edge/User Data/Default")
edge_browser = webdriver.Edge(executable_path = "C:/Users/XYZ/ABC/msedgedriver.exe",options = edge_options )
edge_browser.maximize_window()
WebDriverException: unknown error: MSEdge failed to start: crashed. (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.)
Note: Edge browser is getting invoked and works properly when I run the code without the following line
edge_options.add_argument("user-data-dir = C:/Users/XYZ/AppData/Local/Microsoft/Edge/User Data/Default")
CodePudding user response:
I came across the issue before, that's because there're running Edge processes in the background. The solution is you can back up your User Data
folder in the same path and use that folder in selenium:
Back up your
User Data
folder in the same path. Here for example, I back up theUser Data
folder asUser Data1
:Use
User Data1
in your code to specify using Default profile when run Edge with Selenium:from selenium import webdriver from selenium.webdriver.edge.service import Service edge_options = webdriver.EdgeOptions() #Here you set the path of the back up profile ending with User Data1 not the profile folder edge_options.add_argument("user-data-dir=C:\\Users\\XYZ\\AppData\\Local\\Microsoft\\Edge\\User Data1") ser = Service("C:\\Users\\XYZ\\ABC\\msedgedriver.exe") edge_browser = webdriver.Edge(options = edge_options, service=ser) edge_browser.maximize_window()