I have installed Selenium web driver in my .NET desktop application from the NuGet package manager.
Note: this is a .NET framework project, not an .NET Core or web project.
Now every time there is a update to Chrome, the older version of this installed package crashes my app. And I have to update it manually. So I thought I can check and update the web driver every time I run my app.
What I have tried
// ID of the package to be looked upstring packageID = "Selenium.WebDriver.ChromeDriver";string pathToMyAppFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);// Connect to the official package repository IPackageRepositoryIPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");// Get the list of all NuGet packages with ID 'Selenium.WebDriver.ChromeDriver'List<IPackage> packages = repo.FindPackagesById(packageID).ToList();// Filter the list of packages that are Release (Stable) versions and select the latest versionstring latestVersion = packages.Where(item => (item.IsReleaseVersion() == true)).Max(p => p.Version).ToString();// Initialize the package manager string path = <PATH_TO_WHERE_THE_PACKAGES_SHOULD_BE_INSTALLED>PackageManager packageManager = new PackageManager(repo, path);// Update the package packageManager.UpdatePackage(packageID, SemanticVersion.Parse(latestVersion), true, false);
Where I'm stuck
// Update the package packageManager.UpdatePackage(packageID, SemanticVersion.Parse(latestVersion), true, false);
On this line, I get an error:
Unable to find package 'Selenium.WebDriver.ChromeDriver'
When I checked my debug folder, I found only chromedriver.exe
there. I found that NuGet has installed the entire webdriver package in the packages
folder of the project that I'm working on. Something like this:
C:\path\to\VisualStudio\projects\ProjectFolder\packages\Selenium.WebDriver.ChromeDriver.101.0.4951.4100\driver\win32\chromedriver.exe
I want to update this package at form load event itself.
Can anyone please help me with this? Thanks in advance.