import { escapeCss } from '../utils/Escape' ; import { BaseLocator } from './Locator' ; import { LinkTextLocator , VisibleTextLocator , CSSLocator , TagNameLocator , XPathLocator , EvalLocator , } from './locators/index' ; import { Locator , EvaluateFn } from './types' ; class export class By { param selector public static css ( selector , debugString ? ) { if ( debugString === undefined ) { debugString = `By.css('${ selector }')` ; } return new BaseLocator ( new CSSLocator ( selector ) , debugString ) ; } param { string } id public static id ( id ) { if ( id . startsWith ( '#' ) ) id = id . slice ( 1 ) ; return this . css ( `*[id="${ escapeCss ( id ) }"]` , `By.id('#${ id }')` ) ; } param { string } text static linkText ( text ) { const builder = new LinkTextLocator ( text , false ) ; return new BaseLocator ( builder , `By.linkText('${ text }')` ) ; } param { string } text static partialLinkText ( text ) { const builder = new LinkTextLocator ( text , true ) ; return new BaseLocator ( builder , `By.partialLinkText('${ text }')` ) ; } param { string } text static visibleText ( text ) { const builder = new VisibleTextLocator ( text , false ) ; return new BaseLocator ( builder , `By.visibleText('${ text }')` ) ; } param { string } text static partialVisibleText ( text ) { const builder = new VisibleTextLocator ( text , true ) ; return new BaseLocator ( builder , `By.partialVisibleText('${ text }')` ) ; } param { ! ( string | Function ) } script param { ... * } var_args static js ( script , ... args ) { return new BaseLocator ( new EvalLocator ( script , script , args ) , 'By.js(function)' ) ; } param { string } value return { ! By } public static nameAttr ( value ) { return this . css ( `*[name="${ escapeCss ( value ) }"]` , `By.nameAttr('${ value }')` ) ; } /**
     * Locates an element where the attribute matches the value.
     *
     * **Example:**
     * By.attr('name', 'frame-name')
     */ public static attr ( tagName , attrName , attrValue ) { return this . css ( `${ escapeCss ( tagName ) . toLowerCase ( ) }[${ escapeCss ( attrName ) }="${ escapeCss ( attrValue ) }"]` , `By.attr('${ tagName }','${ attrName }','${ attrValue }')` ) ; } param { string } name return { ! By } static tagName ( name ) { return new BaseLocator ( new TagNameLocator ( name ) , `By.tagName('${ name }')` ) ; } /**
     * Locates elements matching a XPath selector. Care should be taken when
     * using an XPath selector with a  webdriver . WebElement as WebDriver
     * will respect the context in the specified in the selector. For example,
     * given the selector `//div`, WebDriver will search from the document root
     * regardless of whether the locator was used with a WebElement.
     *
     *  param { string } xpath return { ! By } see http static xpath ( xpath ) { return new BaseLocator ( new XPathLocator ( xpath ) , `By.xpath('${ xpath }')` ) ; } }