1

i use this code to open edge browser or chrome browser :

 int ProcessID = -1;
 public enum BrowserType
    {
        Chrome=1,
        Edge=2
    }
 public void OpenChrome(
       string Website,
       int TimeToWaitInMinutes,
       string FolderPathToStoreSession,
       out int ChromeProcessID)
        {

            try
            {

                //chrome process id
                int ProcessID = -1;

                //time to wait until open chrome
                var TimeToWait = TimeSpan.FromSeconds(TimeToWaitInMinutes);

                if (browserValue == BrowserType.Chrome)
                {
                    ChromeDriverService cService = ChromeDriverService.CreateDefaultService();
                    //hide dos screen
                    cService.HideCommandPromptWindow = true;
                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("--user-data-dir=" + FolderPathToStoreSession);
                    options.AddArguments("chrome.switches", "--disable-extensions");
                    driver_Ref = new ChromeDriver(cService, options, TimeToWait);
                    ProcessID = cService.ProcessId;
                }
                else
                {

                    EdgeDriverService cService = EdgeDriverService.CreateDefaultService(".", "msedgedriver.exe");
                    //hide dos screen
                    cService.HideCommandPromptWindow = true;

                    EdgeOptions options = new EdgeOptions();


                    options.AddArgument("--user-data-dir=" + FolderPathToStoreSession);
                    driver_Ref = new EdgeDriver(cService, options, TimeToWait);
                    ProcessID = cService.ProcessId;
                }
                driver_Ref.Navigate().GoToUrl(Website);

                ChromeProcessID = ProcessID;

            }
            catch (Exception ex)
            {
                if (driver_Ref != null)
                {
                    try
                    {
                        driver_Ref.Close();
                        driver_Ref.Quit();
                        driver_Ref.Dispose();
                    }
                    catch { }
                }

                driver_Ref = null;

                ChromeProcessID = -1;
                throw ex;
            }
        }

i use:

  • Microsoft.Edge.SeleniumTools 3.141.3
  • Selenium.Support 3.141.0
  • Selenium.WebDriver 3.141.0
  • Selenium.WebDriver.MSEdgeDriver 105.0.1343.27
  • Microsoft Edge Version 105.0.1343.42 (Official build) (64-bit)

the code is worked fine when i use chrome browser and seesion saved, i mean the login and other browser data are saved to FolderPathToStoreSession, FolderPathToStoreSession is found on application data ,but when i use edge browser session not saved , no error happened, but login and other browser data not saved ,this code not working:

options.AddArgument("--user-data-dir=" + FolderPathToStoreSession);

if you notice that the only difference between code chrome and code edge is :

options.AddArguments("chrome.switches", "--disable-extensions");

please help me to fix this problem.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
Fath Bakri
  • 161
  • 1
  • 12
  • Are you getting an error, or does the browser start, but the session fails to save without any notification? – Greg Burghardt Sep 22 '22 at 12:24
  • Where is the session being stored? I see `FolderPathToStoreSession` but I don't see where the value is being set. You can remove personal information from the folder path. For example, you can use `C:\Users\\a\b`. – Greg Burghardt Sep 22 '22 at 12:26
  • And what users is running your application? Maybe this is a permissions issue with the folder in which you want the session stored? – Greg Burghardt Sep 22 '22 at 12:29
  • i edited my question and provide more details – Fath Bakri Sep 22 '22 at 14:23
  • Can you please fix the whitespace formatting? The code is messy and difficult to read. – Greg Burghardt Sep 22 '22 at 14:23
  • When running Chrome or Edge, is the session data saved to the exact same folder, or different folders? What is the runtime values of `FolderPathToStoreSession` when running Chrome and Edge? – Greg Burghardt Sep 22 '22 at 16:46
  • When running Chrome or Edge, is the session data saved to the exact same folder, or different folders? not extract folder , for example session folder for chrome is 'C:\Users\EMC\AppData\Roaming\Search T\TSessionsFolder\s1_Chrome' , session folder for edge is 'C:\Users\EMC\AppData\Roaming\Search T\TSessionsFolder\s1_Edge' – Fath Bakri Sep 23 '22 at 01:42

1 Answers1

2

i have to change :

EdgeDriverService cService = EdgeDriverService.CreateDefaultService(".", "msedgedriver.exe");

to :

EdgeDriverService cService = EdgeDriverService.CreateChromiumService(".", "msedgedriver.exe");

and add :

options.UseChromium = true;

and it worked fine.

Fath Bakri
  • 161
  • 1
  • 12
  • Good grief. You would think if Chromium is the default rendering engine for Edge, that it would also be the default for its web driver. How many fistfuls of hair did you lose figuring this one out? – Greg Burghardt Sep 23 '22 at 11:10