I am trying to use WebDriverManager Package for .Net for automatically managing the chromedriver.exe version while executing a test case. But when ever I try to type cast ChromeDriver object to RemoteDriverObject it is showing me below error.
Unable to cast object of type 'OpenQA.Selenium.Chrome.ChromeDriver' to type 'OpenQA.Selenium.Remote.RemoteWebDriver'.
I will write the methods and the code that I am using below:
public IWebDriver WebInit()
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--test-type");
options.AddArguments("--start-maximized");
options.AddArguments("--disable-infobars");
options.AddArguments("--disable-extensions");
options.AddAdditionalCapability("useAutomationExtension", false);
options.AddArguments("--ignore-certificate-errors");
options.AddExcludedArgument("enable-automation");
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
options.AddAdditionalCapability("useAutomationExtension", false);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.default_directory", downloadFilepath);
options.AddUserProfilePreference("safebrowsing.enabled", true);
options.AddArguments("window-size=1600,900");
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser); //this is the code used from the mentioned Github Repository
_driver = new ChromeDriver(options);
}
public void FunctionWhereIAmCallingTheWebInitFucntion()
{
_driver = WebInit()
ICapabilities capabilities = ((RemoteWebDriver)_driver).Capabilities; //whenever this line gets executed it throws the exception that is mentioned
}
Below are the Package versions that I am using
<PackageReference Include="Selenium.Support" Version="4.1.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.1" />
<PackageReference Include="WebDriverManager" Version="2.12.4" />
Please can anyone from the community can guide me where am I making a mistake? Thank you very much!!