Skip to content

jQuery Extensions

Lukasz Rajchel edited this page Jun 4, 2018 · 4 revisions

jQuery Selectors

Selenium.WebDriver.Extensions library constains the implementation of jQuery selector that allows to utilize many of jQuery API features in Selenium. To have access to jQuery selector you need to reference the proper By class. The easiest method to do that is by adding following directive.

using By = Selenium.WebDriver.Extensions.By;

You can then use jQuery selectors in a similar way as build-in Selenium selectors.

var result = driver.FindElement(By.JQuerySelector("div:visible"));

If you don't want to override the By instance with using statement, you can still perform the search by creating JQuerySelector objects manually.

var result = driver.FindElement(new JQuerySelector("div:visible"));

jQuery loading

The library can detect whether jQuery has been loaded on the page being tested and if it's not present it will be automatically loaded. However you can also control which version of the jQuery to use or even provide your own source for the jQuery library which can be useful if you run tests on a machine that doesn't have access to internet.

// loads given version
driver.LoadJQuery("1.11.1");

// load given library from URL
driver.LoadJQuery(new Uri("http://myserver.com/jquery-1.11.1.min.js"));
Clone this wiki locally