Skip to content

vinzh05/SeleniumHelper

Repository files navigation

SeleniumSupport Library

Enhance your Selenium experience with streamlined functionality!

What's new?

*Update Version 1.0.7 In the new version 1.0.7, you can now Screenshot the Chrome to Base64, Add BrowserPath, driverPath and Get value from ExcuteJS!

Download and install to experience the new version now!

Download on nuget: https://www.nuget.org/packages/Selenium.SeleniumHelper

From now on when you take a selenium screenshot, it will return the result in base64 format making your image capture more convenient:

  • For an driver screenshot, set type to "driver".

  • For an element screenshot, set type to "element".

Screenshot Selenium Guide.

  • Driver screenshot

    IWebDriver driver = null;
    SeleniumHelper.TakeScreenShotToBase64(driver, "driver");
    
  • Element screenshot

    IWebDriver driver = null;
    var element = iwebdriver.FindElement(By.XPath("abcxyz"));
    SeleniumHelper.TakeScreenShotToBase64(driver, "element", element);
    

Add BrowserPath & DriverPath Selenium Guide.

  • BrowserPath
     seleniumHelper.UseBrowserPath = true;
     seleniumHelper.BrowserPath = "abcxyz";
    
  • DriverPath
    seleniumHelper.UseDriverPath = true;
    seleniumHelper.DriverPath = "abcxyz";
    

ExcuteJS.

  • Get value from ExcuteJS
    var height = SeleniumHelper.ExcuteJS(driver, "return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");
  • Use ExcuteJS
    SeleniumHelper.ExcuteJS(driver, "return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");
    

Version 1.0.3: In the new version 1.0.3, you can now add a Proxy containing authentication directly to Chrome!

Download and install to experience the new version now!

Download on nuget: https://www.nuget.org/packages/Selenium.SeleniumHelper

To configure a proxy in your settings, use the following guidelines:

  • For an HTTP proxy, set TypeProxy to 0.

  • For a SOCKS5 proxy, set TypeProxy to 1.

The proxy configuration should be specified in one of these formats:

  • ip:port for simple IP address and port configuration.

  • ip:port:user:pass if authentication with a username and password is required.

Make sure to choose the correct format based on your proxy type and whether authentication is needed.

  • Proxy have ip:port
     seleniumHelper.TypeProxy = 0;
     seleniumHelper.Proxyaddress = "a:b";
    
  • Proxy have ip:port:user:pass
    seleniumHelper.TypeProxy = 0;
    seleniumHelper.Proxyaddress = "a:b:c:d";

Description

SeleniumSupport is a robust library created to simplify and enhance your Selenium-based automation tasks. It introduces user-friendly methods and configurations to streamline browser manipulation and interaction. Key features include disabling images for speed, using browser extensions, managing multiple profiles, and proxy configurations. With SeleniumSupport, developers can automate more efficiently, reducing the boilerplate code typically associated with Selenium.

Getting Started

Dependencies

  • Ensure you have Selenium WebDriver installed.
  • Compatible with major operating systems (e.g., Windows, macOS, Linux).

Installing

Executing program

Execute your Selenium scripts with enhanced capabilities:

  • Usage:
  • var helper = new SeleniumHelper();
    var driver = SeleniumHelper.OpenBrowser(helper);
    // Your automation code here

Detailed Usage Guide

Initialize chrome

  1. OpenBrowser(SeleniumHelper seleniumHelper)
  • Purpose: Initializes and returns a ChromeDriver instance configured with options specified in the SeleniumHelper instance.

  • Usage:

    ChromeDriver driver = null;
    SeleniumHelper seleniumHelper = new SeleniumHelper();
    seleniumHelper.DisableImages = false;
    seleniumHelper.UseExtension = false;
    seleniumHelper.UseAppMode = false;
    seleniumHelper.ExtensionPath = "";
    seleniumHelper.UseDebugPort = false;
    seleniumHelper.DebugPort = "";
    seleniumHelper.UseProfile = true;
    seleniumHelper.ProfilePath = uidProfile;
    seleniumHelper.ProxyType = 0;
    seleniumHelper.ProxyAddress = "";
    driver = SeleniumHelper.OpenChrome(seleniumHelper);
  1. WaitElement(IWebDriver driver, string type, string element, int repeat, int timeDelay)
  • Purpose: Waits for an element to become available on the web page, retrying a specified number of times.

  • Usage:

    bool isElementFound = SeleniumHelper.WaitElement(driver, "id", "submit-button", 5, 1);
  1. CheckPageSource(IWebDriver driver, int timeWait, string text)
  • Purpose: Checks if a specific text is present in the page source within a specified time period.

  • Usage:

    bool isTextFound = SeleniumHelper.CheckPageSource(driver, 3, "Welcome");
  1. ExcuteJS(IWebDriver driver, string command)
  • Purpose: Executes JavaScript on the current page.

  • Usage:

    SeleniumHelper.ExcuteJS(driver, "alert('Hello World');");

Tab and Window Handling Methods

  1. OpenNewTab(IWebDriver driver):
  • Opens a new browser tab.

  • Example:

    SeleniumHelper.OpenNewTab(driver);
  1. SwitchtoFirstTab(IWebDriver driver), SwitchtoLastTab(IWebDriver driver), SwitchtoCloseFirstTab(IWebDriver driver), SwitchtoCloseLastTab(IWebDriver driver):
  • Manage browser tabs by switching to or closing the first or last tab.

  • Example:

    SeleniumHelper.SwitchtoFirstTab(driver);
    SeleniumHelper.CloseDriver(driver);

Additional Utilities

  1. AddCookieIntoChrome(IWebDriver driver, string cookie, string domain):
  • Adds a cookie into Chrome.

  • Example:

    SeleniumHelper.AddCookieIntoChrome(driver, "sessionId=abc123", "example");
  1. GetCookieFromChrome(IWebDriver driver):
  • Retrieves cookies from Chrome.

  • Example:

    string cookies = SeleniumHelper.GetCookieFromChrome(driver);
    

Authors

Version History

  • 1.0.3

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Donations

Support the ongoing development and improvement of SeleniumSupport:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages