@theintern/leadfoot
Version:
Leadfoot. A JavaScript client library that brings cross-platform consistency to the Selenium WebDriver API.
358 lines • 12.7 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toW3cLocator = exports.strategies = exports.w3cStrategies = void 0;
/**
* Locator is a class that supports searching for specific element (E), list
* (L), and void (V) types by various strategies.
*
* Note that this class includes JSONWireProtocol strategies. W3C Webdriver
* only understands 4 strategies:
*
* 1. css selector
* 2. link text
* 3. partial link text
* 4. xpath
*/
var Locator = /** @class */ (function () {
function Locator() {
}
/**
* Gets the first element inside this element matching the given CSS class
* name.
*
* @param className The CSS class name to search for.
*/
Locator.prototype.findByClassName = function (className) {
return this.find('class name', className);
};
/**
* Gets the first element inside this element matching the given CSS
* selector.
*
* @param selector The CSS selector to search for.
*/
Locator.prototype.findByCssSelector = function (selector) {
return this.find('css selector', selector);
};
/**
* Gets the first element inside this element matching the given ID.
*
* @param id The ID of the element.
*/
Locator.prototype.findById = function (id) {
return this.find('id', id);
};
/**
* Gets the first element inside this element matching the given name
* attribute.
*
* @param name The name of the element.
*/
Locator.prototype.findByName = function (name) {
return this.find('name', name);
};
/**
* Gets the first element inside this element matching the given
* case-insensitive link text.
*
* @param text The link text of the element.
*/
Locator.prototype.findByLinkText = function (text) {
return this.find('link text', text);
};
/**
* Gets the first element inside this element partially matching the given
* case-insensitive link text.
*
* @param text The partial link text of the element.
*/
Locator.prototype.findByPartialLinkText = function (text) {
return this.find('partial link text', text);
};
/**
* Gets the first element inside this element matching the given HTML tag
* name.
*
* @param tagName The tag name of the element.
*/
Locator.prototype.findByTagName = function (tagName) {
return this.find('tag name', tagName);
};
/**
* Gets the first element inside this element matching the given XPath
* selector.
*
* @param path The XPath selector to search for.
*/
Locator.prototype.findByXpath = function (path) {
return this.find('xpath', path);
};
/**
* Gets all elements inside this element matching the given CSS class name.
*
* @param className The CSS class name to search for.
*/
Locator.prototype.findAllByClassName = function (className) {
return this.findAll('class name', className);
};
/**
* Gets all elements inside this element matching the given CSS selector.
*
* @param selector The CSS selector to search for.
*/
Locator.prototype.findAllByCssSelector = function (selector) {
return this.findAll('css selector', selector);
};
/**
* Gets all elements inside this element matching the given name attribute.
*
* @param name The name of the element.
*/
Locator.prototype.findAllByName = function (name) {
return this.findAll('name', name);
};
/**
* Gets all elements inside this element matching the given
* case-insensitive link text.
*
* @param text The link text of the element.
*/
Locator.prototype.findAllByLinkText = function (text) {
return this.findAll('link text', text);
};
/**
* Gets all elements inside this element partially matching the given
* case-insensitive link text.
*
* @param text The partial link text of the element.
*/
Locator.prototype.findAllByPartialLinkText = function (text) {
return this.findAll('partial link text', text);
};
/**
* Gets all elements inside this element matching the given HTML tag name.
*
* @param tagName The tag name of the element.
*/
Locator.prototype.findAllByTagName = function (tagName) {
return this.findAll('tag name', tagName);
};
/**
* Gets all elements inside this element matching the given XPath selector.
*
* @param path The XPath selector to search for.
*/
Locator.prototype.findAllByXpath = function (path) {
return this.findAll('xpath', path);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given CSS class name. This is inherently slower
* than [[Element.find]], so should only be used in cases where the
* visibility of an element cannot be ensured in advance.
*
* @since 1.6
* @param className The CSS class name to search for.
*/
Locator.prototype.findDisplayedByClassName = function (className) {
return this.findDisplayed('class name', className);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given CSS selector. This is inherently slower than
* [[Element.find]], so should only be used in cases where the visibility
* of an element cannot be ensured in advance.
*
* @since 1.6
* @param selector The CSS selector to search for.
*/
Locator.prototype.findDisplayedByCssSelector = function (selector) {
return this.findDisplayed('css selector', selector);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given ID. This is inherently slower than
* [[Element.find]], so should only be used in cases where the visibility
* of an element cannot be ensured in advance.
*
* @since 1.6
* @param id The ID of the element.
*/
Locator.prototype.findDisplayedById = function (id) {
return this.findDisplayed('id', id);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given name attribute. This is inherently slower
* than [[Element.find]], so should only be used in cases where the
* visibility of an element cannot be ensured in advance.
*
* @since 1.6
* @param name The name of the element.
*/
Locator.prototype.findDisplayedByName = function (name) {
return this.findDisplayed('name', name);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given case-insensitive link text. This is
* inherently slower than [[Element.find]], so should only be used in cases
* where the visibility of an element cannot be ensured in advance.
*
* @since 1.6
* @param text The link text of the element.
*/
Locator.prototype.findDisplayedByLinkText = function (text) {
return this.findDisplayed('link text', text);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element partially matching the given case-insensitive link text. This is
* inherently slower than [[Element.find]], so should only be used in cases
* where the visibility of an element cannot be ensured in advance.
*
* @since 1.6
* @param text The partial link text of the element.
*/
Locator.prototype.findDisplayedByPartialLinkText = function (text) {
return this.findDisplayed('partial link text', text);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given HTML tag name. This is inherently slower than
* [[Element.find]], so should only be used in cases where the visibility
* of an element cannot be ensured in advance.
*
* @since 1.6
* @param tagName The tag name of the element.
*/
Locator.prototype.findDisplayedByTagName = function (tagName) {
return this.findDisplayed('tag name', tagName);
};
/**
* Gets the first [[Element.isDisplayed|displayed]] element inside this
* element matching the given XPath selector. This is inherently slower
* than [[Element.find]], so should only be used in cases where the
* visibility of an element cannot be ensured in advance.
*
* @since 1.6
* @param path The XPath selector to search for.
*/
Locator.prototype.findDisplayedByXpath = function (path) {
return this.findDisplayed('xpath', path);
};
/**
* Waits for all elements inside this element matching the given CSS class
* name to be destroyed.
*
* @param className The CSS class name to search for.
*/
Locator.prototype.waitForDeletedByClassName = function (className) {
return this.waitForDeleted('class name', className);
};
/**
* Waits for all elements inside this element matching the given CSS
* selector to be destroyed.
*
* @param selector The CSS selector to search for.
*/
Locator.prototype.waitForDeletedByCssSelector = function (selector) {
return this.waitForDeleted('css selector', selector);
};
/**
* Waits for all elements inside this element matching the given ID to be
* destroyed.
*
* @param id The ID of the element.
*/
Locator.prototype.waitForDeletedById = function (id) {
return this.waitForDeleted('id', id);
};
/**
* Waits for all elements inside this element matching the given name
* attribute to be destroyed.
*
* @param name The name of the element.
*/
Locator.prototype.waitForDeletedByName = function (name) {
return this.waitForDeleted('name', name);
};
/**
* Waits for all elements inside this element matching the given
* case-insensitive link text to be destroyed.
*
* @param text The link text of the element.
*/
Locator.prototype.waitForDeletedByLinkText = function (text) {
return this.waitForDeleted('link text', text);
};
/**
* Waits for all elements inside this element partially matching the given
* case-insensitive link text to be destroyed.
*
* @param text The partial link text of the element.
*/
Locator.prototype.waitForDeletedByPartialLinkText = function (text) {
return this.waitForDeleted('partial link text', text);
};
/**
* Waits for all elements inside this element matching the given HTML tag
* name to be destroyed.
*
* @param tagName The tag name of the element.
*/
Locator.prototype.waitForDeletedByTagName = function (tagName) {
return this.waitForDeleted('tag name', tagName);
};
/**
* Waits for all elements inside this element matching the given XPath
* selector to be destroyed.
*
* @param path The XPath selector to search for.
*/
Locator.prototype.waitForDeletedByXpath = function (path) {
return this.waitForDeleted('xpath', path);
};
return Locator;
}());
exports.default = Locator;
exports.w3cStrategies = {
'css selector': true,
'link text': true,
'partial link text': true,
xpath: true
};
exports.strategies = __assign(__assign({}, exports.w3cStrategies), { 'class name': true, id: true, name: true, 'partial link text': true, 'tag name': true });
function toW3cLocator(using, value) {
switch (using) {
case 'id':
using = 'css selector';
value = "#" + value;
break;
case 'class name':
using = 'css selector';
value = "." + value;
break;
case 'name':
using = 'css selector';
value = "[name=\"" + value + "\"]";
break;
case 'tag name':
using = 'css selector';
break;
}
return { using: using, value: value };
}
exports.toW3cLocator = toW3cLocator;
//# sourceMappingURL=Locator.js.map