Class SeleniumHelper
- Namespace
- SunamoSelenium
- Assembly
- SunamoSelenium.dll
Helper class for initializing and managing Selenium WebDriver instances.
public class SeleniumHelper
- Inheritance
-
SeleniumHelper
- Inherited Members
- Extension Methods
Methods
InitChromeDriver(ILogger, ChromeOptions?, bool)
Initializes a Chrome WebDriver instance using built-in Selenium Manager (Selenium 4.6+) for automatic driver download and management. After initialization, register the driver via ServiceCollection.AddSingleton(typeof(IWebDriver), driver).
public static Task<IWebDriver?> InitChromeDriver(ILogger logger, ChromeOptions? options = null, bool isThrowingException = false)
Parameters
loggerILoggerThe logger instance for diagnostic output.
optionsChromeOptionsOptional Chrome browser options. If null, default options are created.
isThrowingExceptionboolWhen true, throws an exception on failure instead of returning null.
Returns
- Task<IWebDriver>
An initialized OpenQA.Selenium.IWebDriver instance or null on failure.
InitDriver(ILogger, EdgeOptions?, bool)
Alias for InitEdgeDriver(ILogger, EdgeOptions?, bool) for backward compatibility. Initializes Edge WebDriver using built-in Selenium Manager (automatic driver download).
public static Task<IWebDriver?> InitDriver(ILogger logger, EdgeOptions? options = null, bool isThrowingException = false)
Parameters
loggerILoggerThe logger instance for diagnostic output.
optionsEdgeOptionsOptional Edge browser options.
isThrowingExceptionboolWhen true, throws an exception on failure instead of returning null.
Returns
- Task<IWebDriver>
An initialized OpenQA.Selenium.IWebDriver instance or null on failure.
InitEdgeDriver(ILogger, EdgeOptions?, bool)
Initializes an Edge WebDriver instance using built-in Selenium Manager (Selenium 4.6+) for automatic driver download and management. After initialization, register the driver via ServiceCollection.AddSingleton(typeof(IWebDriver), driver).
public static Task<IWebDriver?> InitEdgeDriver(ILogger logger, EdgeOptions? options = null, bool isThrowingException = false)
Parameters
loggerILoggerThe logger instance for diagnostic output.
optionsEdgeOptionsOptional Edge browser options. If null, default options are created.
isThrowingExceptionboolWhen true, throws an exception on failure instead of returning null.
Returns
- Task<IWebDriver>
An initialized OpenQA.Selenium.IWebDriver instance or null on failure.
InitEdgeDriver(ILogger, string, EdgeOptions?, bool)
OBSOLETE: Do NOT use hardcoded driver paths. This method throws an exception. Always use Selenium Manager for automatic driver management by calling InitEdgeDriver(ILogger, EdgeOptions?, bool) without path parameter.
[Obsolete("Do NOT use hardcoded driver paths! Use InitEdgeDriver(logger, options) without driverPath parameter. Selenium Manager will automatically download the correct driver version.", true)]
public static Task<IWebDriver?> InitEdgeDriver(ILogger logger, string driverPath, EdgeOptions? options = null, bool isThrowingException = false)
Parameters
loggerILoggerThe logger instance for diagnostic output.
driverPathstringThe hardcoded driver path (not supported).
optionsEdgeOptionsOptional Edge browser options.
isThrowingExceptionboolWhen true, throws an exception on failure instead of returning null.
Returns
- Task<IWebDriver>
Never returns; always throws InvalidOperationException.
OpenChromeDriverDownloadPage()
Opens the ChromeDriver download page in the default browser.
public static void OpenChromeDriverDownloadPage()
OpenEdgeDriverDownloadPage()
Opens the EdgeDriver download page in the default browser.
public static void OpenEdgeDriverDownloadPage()