Ajmal Moideen
Ajmal Moideen

Reputation: 230

Selenium - Edge - How to start a webdriver session with work profile?

My application does not have a login page to get authenticated. It uses my organizational email id (SSO) to authenticate my access to the application. I am using Version 80.0.361.66 (Official build) (64-bit) of Microsoft Edge.

driver = webdriver.Edge()
driver.maximize_window()

selenium version - selenium==3.141.0

This edge session does not use my work profile . It opens a new session because of which my work profile is not loaded and my access to the application is denied. However, I did try to update the version of selenium to use EdgeOptions. But, that didn't work as well. Below is the code :

options = webdriver.EdgeOptions() 
options.add_argument("user-data-dir=C:\\Users\\Ajmal.Moideen\\AppData\\Local\\Microsoft\\Edge\\User Data") 
driver = webdriver.Edge(options=options) 
driver.maximize_window() 

selenium version=4.0.0a3

Upvotes: 2

Views: 6660

Answers (1)

datu-puti
datu-puti

Reputation: 1363

Here's how I got it to work - I am using Chromium Edge 85.0.564.51 with Selenium 3.141.0.

Selenium 3.141.0 from pip doesn't seem to support new Chromium-based Edge Webdriver, but Microsoft supplies it in their msedge-selenium-tools package (better documentation here) as mentioned by Matthias' comment on your question.

First, grab the Chromium Edge webdriver here - get the version that matches your version of Edge (go to chrome:version in Edge to see what version you are running). Put the webdriver somewhere convenient, you need to set driverpath below to point to it.

Install the pip packages:

pip install msedge-selenium-tools selenium==3.141

In your code, import the msedge-selenium-tools Webdriver and Options modules and build the webdriver as shown:

from msedge.selenium_tools import Edge, EdgeOptions

...

options = EdgeOptions()
options.use_chromium = True
options.add_argument("--user-data-dir=C:\\Users\\YOUR-USERNAME\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("--start-maximized")
driverpath = 'msedgedriver.exe'

driver = Edge(driverpath, options=options)

Voilà, that should do the trick.

P.S.: Even though chrome:version will show your Profile path with a trailing \Default, don't include that in your --user-data-dir argument above, since the driver seems to append \Default to the end.

Upvotes: 3

Related Questions