GithubHelp home page GithubHelp logo

wndrr / seleniumutils Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 17 KB

A C#.NET Standard 2.0 collection of utility methods for Selenium Webdriver

Home Page: https://www.nuget.org/packages/Wndrr.Selenium.Utils

License: The Unlicense

C# 100.00%
selenium seleniumwebdriver csharp-library net-standard-2

seleniumutils's Introduction

Selenium utils

A C#.NET Standard 2.0 collection of utility methods for Selenium Webdriver

Compatibility

This library targets .NET Standard 2.0 which makes it compatible with both .NET Core 2.0 and above aswell as .NET Framework 4.6.1 and above. See the compatibility page for a more exhaustive list of compatible frameworks.

NuGet package

The NuGet package can be found on NuGet.org or by searching Wndrr.Selenium.Utils in the NuGet explorer.

Usage

The VerticalScrollTo extension method

Replaces the ScrollTo method

Tries to put an element in the center of the screen vertically using a javascript call to window.scrollTo. Usage example

// Instanciate an IWebDriver
using (var driver = new ChromeDriver())
{
    // Find an element in the DOM (isn't "dummyElement" a very cute name for an ID ?)
    var dummyElement = _driver.FindElement(By.Id("dummyElement"));
    // Scroll the element to the center of the window (more or less) 
    driver.VerticalScrollTo(dummyElement);
}

The SwitchToTab extension method

Changes the focus of the IWebDriver to target the tab/window, finding it by its id. The return value indicates if the tab could be found. When it is false no tab change occured.

// Instanciate an IWebDriver
using (var driver = new ChromeDriver())
{
    // Focus to the 2nd tab
    bool isSwitchSuccess = driver.SwitchToTab(1);
}

The WaitUntilCurrentUrlChange extension method

Periodically checks if the browser URL has changed. If no changes occured before the specified timeout occurs, a TimeoutException will be thrown.

// Instanciate an IWebDriver
using (var driver = new ChromeDriver())
{
    // Will wait untill the URL changes using the default timeout (10s) and poll (.5s) time
    driver.WaitUntilCurrentUrlChange();
}

The WaitUntilUrlIs extension method

Periodically checks if the browser URL is identical to the passed string. If the URL does not match before the specified timeout occurs, a TimeoutException will be thrown.

// Instanciate an IWebDriver
using (var driver = new ChromeDriver())
{
    // Will wait untill the URL becomes https://request.url using the default timeout (10s) and poll (.5s) time
    driver.WaitUntilUrlIs("https://request.url");
}

The WaitUntilUrlContains extension method

Periodically checks if the browser URL contains the passed string. If the URL does not match before the specified timeout occurs, a TimeoutException will be thrown.

// Instanciate an IWebDriver
using (var driver = new ChromeDriver())
{
    // Will wait untill the URL becomes https://request.url using the default timeout (10s) and poll (.5s) time
    driver.WaitUntilUrlContains("/part/of/url?wololo=pouët");
}

Legacy code

The ScrollTo was made obsolete. Use VerticalScrollTo instead.

seleniumutils's People

Contributors

mathieuctv avatar wndrr avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.