1

I'm running Selenium 4.0.0-beta1 on MSVC 2019 using C#.

I'm using MicrosoftDriver version 17.17134.0.

Whenever I use Selenium to perform automated browsing, the browsing history is not saved after the session. I would like to keep a persistent browsing history state.

I got some answers from, Save and load browser history for selenium.

But I'm not sure how to replicate the Java solution for Firefox in C# for Microsoft Edge.

In particular, I couldn't find the equivalent profile object to import or create a profile for the browser history.

var edgedriverservice = EdgeDriverService.CreateDefaultService();
var edgeoptions = new EdgeOptions();
var driver = new EdgeDriver(edgedriverservice, edgeoptions);

I have setup my new driver object in the following manner, I'm not sure how the profile object fits in from the previous link.

chou
  • 13
  • 2
  • Do you want to keep the browser history when using selenium webdriver? The history is not saved because the webdriver creates a new browser profile each time it launches the browser. I suggest that you can move to the latest [Edge Chromium](https://www.microsoft.com/en-us/edge) browser. In this situation, you can easily achieve what you want by telling the Edge driver to use the same profile every time when you launch the browser. – Yu Zhou Feb 26 '21 at 06:07
  • Thanks for commenting @YuZhou yes that is indeed that I want to do. I believe that I'm already using the Edge Chromium. But just to be sure, the version of Edge I'm using is 86.0.622.56. Would you be willing to show some example code on how to use the same profile for Edge Chromium? Thanks. – chou Feb 28 '21 at 04:06

1 Answers1

0

Yes you're using Edge Chromium, then the WebDriver you're using is not right. You need to use the same version WebDriver as the Edge Chromium version in this page. You need to click full version directory and download Edge WebDriver version 86.0.622.56.

The sample code to use the specific profile for Edge Chromium is like below:

EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
// Here you set the path of the profile ending with User Data not the profile folder
edgeOptions.AddArgument(@"user-data-dir=C:\Users\yuzhou\AppData\Local\Microsoft\Edge\User Data");
// Here you specify the actual profile folder
edgeOptions.AddArgument("profile-directory=Profile 4");
IWebDriver driver = new EdgeDriver(edgeOptions);
driver.Navigate().GoToUrl("https://www.google.com");

Note: Change the paths in the code to your owns.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22