Home > Back-end >  C# & Selenium WebDriver 4.0 - Microsoft Edge Profile Selection Window Prevents Tests from Running
C# & Selenium WebDriver 4.0 - Microsoft Edge Profile Selection Window Prevents Tests from Running

Time:03-04

When attempting to build tests using Selenium WebDriver 4.10 and C# (.NET Framework 4.5.2) using the following code I receive a pop-up asking to select a profile. From what I understand the code below already is specifying the profile to use:

string strEdgeProfilePath = @"C:\\Users\\"   Environment.UserName   @"\\AppData\\Local\\Microsoft\\Edge\\User Data";
string strDefautProfilePath = strEdgeProfilePath   @"\\Default";
string strSeleniumProfilePath = strEdgeProfilePath   @"\\Selenium"; // <---- I have deleted this folder and copied the contents of the "Default" folder to no avail.

using (var service = EdgeDriverService.CreateDefaultService(@"C:\Temp\Selenium\Edge")) {
    service.UseVerboseLogging = true;
    EdgeOptions edgeOptions = new EdgeOptions();
    edgeOptions.AddArgument("--user-data-dir="   strSeleniumProfilePath);
    edgeOptions.AddArgument("--profile-directory=Selenium");
    driver = new EdgeDriver(@"C:\Temp\Selenium\Edge", edgeOptions); // <----- msedgeserve.exe located here
}

Even when I select the profile Microsoft Edge does not continue and the test times out.

What can I do to prevent the profile selection and get the test to run?

CodePudding user response:

There're some problems in your code:

  1. You don't need to use double backslash, backslash is enough.
  2. The value for --user-data-dir is not right. Using strEdgeProfilePath for it is enough.

So the right code should be like this:

string strEdgeProfilePath = @"C:\Users\"   Environment.UserName   @"\AppData\Local\Microsoft\Edge\User Data";
...

\\Here you set the path of the profile ending with User Data not the profile folder
edgeOptions.AddArgument("--user-data-dir="   strEdgeProfilePath);

\\Here you specify the actual profile folder
\\If it is Default profile, no need to use this line of code
edgeOptions.AddArgument("--profile-directory=Selenium");

Besides, to avoid running Edge processes errors, you need to follow the back up steps in this answer. Please use the backup folder instead of the original folder in the code.

  • Related