Chromium Edge Browser arguments "user-data-dir"

Hi, How can we use “user-data-dir” argument when using edge browser in robot framework - SeleniumLibrary?

Following is the issue am facing - when ever I open the edge browser using selenium, then Edge browser requires me to login. It does not pick up the existing browser profile. I wanted to avoid the login prompt and right away go to chrome with one of the existing profile.

Following python code works without issues opening edge browser but am unable to use the argument user-data-dir in SeleniumLibrary robot framework

***** Python Code ****
from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.by import By

Launch Microsoft Edge (Chromium)

options = EdgeOptions()
options.use_chromium = True
options.add_argument(‘start-maximized’)
options.add_argument(“user-data-dir=C:\Users\username\AppData\Local\Microsoft\Edge\User Data”)
options.capabilities[‘ignoreProtectedModeSettings’] = True

driver = Edge(options=options)
driver.get(“http://google.com”)

inputElement = driver.find_element(By.XPATH, ‘/html/body/app/main/login/div/form/div[2]/div/input’)
inputElement.send_keys(‘test’)
inputElement = driver.find_element(By.XPATH, ‘/html/body/app/main/login/div/form/div[3]/div/input’)
inputElement.send_keys(‘test’)
inputElement = driver.find_element(By.XPATH,’/html/body/app/main/login/div/form/div[4]/button’)
inputElement.click()

** Following is the code am using in robot ***
Library SeleniumLibrary
*** Test Cases ***
Edge Browser Automation
${URL} Set Variable http://google.com
Open Browser edge options=add_argument(user-data-dir=C:\Users\username\AppData\Local\Microsoft\Edge\User Data)

**new user here - not allowing me to post more than 2 links
I get the following error
Unable to parse option: “add_argument(user-data-dir=C:\Users\nahmed\AppData\Local\Microsoft\Edge\User Data)”

Below is the setup I have
SeleniumLibrary - 5.1.3
Robot Framework - 4.0.1
Edge browser driver - Version: 90.0.818.51: [x86]
Edge Browser version - Version 90.0.818.51 (Official build) (64-bit)

Without doing any tests, I would say that you need to escape the\, like in \\

Sometimes, you need to escape the= like in “user-data-dir\=C:\\Users”.

And care must be taken when using Paths with spaces, so the string would need also to be quoted. For example:
options.add_argument(“user-data-dir='C:\\Users\\username\\AppData\\Local\\Microsoft\\Edge\\User Data'”)

Thanks Helio for the response. Yea I looked into escaping aspect too. But thats not the issue I’m facing currently. For some reason for edge browser - user-data-dir parameter is not being parsed by SeleniumLibrary.

Without which my tests are unable to open edge to navigate to any website as edge prompts to login into a profile.

Is there any way we can overcome this for edge browsers?

Hi Nishar,

I did a quick search to see if there was a known upstream issue (i.e. if it was a known problem with Selenium) - I didn’t find any issue, but I did find this:

I know you said you already tried:
options.add_argument(“user-data-dir=C:\\Users\\username\\AppData\\Local\\Microsoft\\Edge\\User Data”)

so I’ll suggest you try:
options.add_argument(“user-data-dir=C:/Users/username/AppData/Local/Microsoft/Edge/User\ Data”)

Something most people don’t know is that you can use unix style paths in windows, this avoids the whole having to escape path separators issue.

The other thing you should note is the escaping of a space in the path if this doesn’t work can you make a copy of the “User Data” directory to something with out a space i.e. User_Data or UserData then try again without the space:
options.add_argument(“user-data-dir=C:/Users/username/AppData/Local/Microsoft/Edge/UserData”)
or
options.add_argument(“user-data-dir=C:/Users/username/AppData/Local/Microsoft/Edge/User_Data”)

spaces are always trouble makers in paths.

Also the other tip from the stack exchange answer is that you can use the edge://version/ to check the profile path, so if you comment out closing the browser (if you do that) then that might help workout what is happening especially if the profile path comes up as C:\Users\nahmed\AppData\Local\Microsoft\Edge\User (note the " Data" missing)

Hope that helps,

Dave.

Thanks Dave for response. Python code worked for me without any issues.
I’m trying to get it worked with Robot and Edge browser. But I believe we cannot have options while use edge browser when using SeleniumLibrary. I do not see the options method for edge in Webdriver. I do see options methods for Chrome, Firefox and IE.

Hi Nishar,

According the documentation for Open Browser you should be able to simply do:

Open Browser    http://example.com     Edge    user-data-dir=C:/Users/username/AppData/Local/Microsoft/Edge/User_Data

Take particular note of the comment on Windows paths in that section (escape once for python and again for rf) which is why I usually use the unix style path separators on windows.

There was also a note about creating a python function to return the

options = webdriver.ChromeOptions()
options.add_argument('--disable-dev-shm-usage')
return options

Then the ${options} variable can be used as an argument to options .

You could try something similar with Edge

Hopefully something here helps, If not i’m out of ideas,

Dave.

Hi Nishar ,
Were you able to solve the issue with Robot frame work for Microsoft edge for user specific login let me know I am also going through same pain…

Hi Nishar ,
Were you able to solve the issue with Robot frame work for Microsoft edge for user specific login let me know I am also going through same pain…

nishar.qtp
Hi Nishar ,
Were you able to solve the issue with Robot frame work for Microsoft edge for user specific login let me know I am also going through same pain…