Options
All
  • Public
  • Public/Protected
  • All
Menu

Class XPathBuilder

XPathBuilder allows for the creation of XPath expressions using modification functions instead of writing the whole XPath as a raw string.

Using XPathBuilder can help to reduce the number of errors originating from a wrong usage of the sometimes quite complex syntax of XPath.

XPathBuilder implements the singleton pattern - therefore there can only ever by one instance of XPathBuilder which internally stores the currently constructed XPath expression.

To build and retrieve a raw XPath string from the currently constructed XPath expression, call build on XPathBuilder's singleton instance.

Hierarchy

  • XPathBuilder

Index

Properties

Private _selector

_selector: string

Stores the currently constructed XPath expression.

Static Private _instance

_instance: XPathBuilder

Stores the singleton instance of XPathBuilder.

Methods

append

  • append(appendedXPath: string): this
  • Appends a plain XPath string to the currently constructed XPath expression.

    Parameters

    • appendedXPath: string

      the appended plain XPath string

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

attribute

  • attribute(name: string, value?: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute whose name equals the passed name.

    Optionally, if also passing a value, the currently constructed XPath expression is further restricted to elements which have an HTML attribute whose name equals the passed name and whose value equals the passed value.

    Parameters

    • name: string

      the name of the HTML attribute used to restrict the currently constructed XPath expression

    • Optional value: string

      a value that needs to equal the value of the HTML attribute with the passed name

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

attributeContains

  • attributeContains(name: string, value: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute whose name contains the passed name.

    Optionally, if also passing a value, the currently constructed XPath expression is further restricted to elements which have an HTML attribute whose name equals the passed name and whose value contains the passed value.

    Parameters

    • name: string

      the name of the HTML attribute used to restrict the currently constructed XPath expression

    • value: string

      a value that needs to be contained by the value of the HTML attribute with the passed name

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

build

  • build(): string

checked

  • checked(): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'checked'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

child

  • child(childSelector: string): this
  • Appends a childSelector to the currently constructed XPath expression in order to select a child element.

    After executing .child, the selected child element becomes the new "target" for all future XPath modification functions (eg. .id, .class) until the currently constructed XPath expression is reset.

    Parameters

    • childSelector: string

      a selector appended to the currently constructed XPath expression to select a child element

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

class

  • class(className?: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'class'.

    Optionally, if also passing a class name, the currently constructed XPath expression is further restricted to elements which have an HTML 'class' attribute with a value that equals the passed class name.

    Parameters

    • Optional className: string

      a class name which must equal the value of the HTML 'class' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

classContains

  • classContains(className: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'class' with a value that contains the passed class name.

    Parameters

    • className: string

      a class name which must be contained by the value of the HTML 'class' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

constraint

  • constraint(constraintSelector: string, builderFunc?: function): this
  • Adds a plain XPath constraint (eg. '[./span]') to the currently constructed XPath expression.

    Optionally, a builderFunc can be used to apply XPath modification functions to the constraint selector instead of the "outer" selector. To do so, builderFunc is passed an XPathBuilder instance configured to use constraintSelector as a new root for the currently constructed XPath expression.

    Parameters

    • constraintSelector: string

      a plain XPath constraint appended to the currently constructed XPath expression

    • Optional builderFunc: function

      can be used to apply XPath modification functions to constraintSelector

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

disabled

  • disabled(): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'disabled'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

hasChild

  • hasChild(childSelector: string, builderFunc?: function): this
  • Restricts the currently constructed XPath expression to elements which have at least one child element that matches the passed childSelector.

    Optionally, a builderFunc can be used to apply XPath modification functions to the child selector instead of the "outer" selector. To do so, builderFunc is passed an XPathBuilder instance configured to use the childSelector as a new root for the currently constructed XPath expression.

    Parameters

    • childSelector: string

      a plain XPath constraint appended to the currently constructed XPath expression

    • Optional builderFunc: function

      can be used to apply XPath modification functions to childSelector

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

id

  • id(id?: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'id'.

    Optionally, if also passing an id, the currently constructed XPath expression is further restricted to elements which have an HTML 'id' attribute with a value that equals the passed id.

    Parameters

    • Optional id: string

      an id which must equal the value of the HTML 'id' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

idContains

  • idContains(id: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'id' with a value that contains the passed id.

    Parameters

    • id: string

      an id which must be contained by the value of the HTML 'id' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

index

  • index(index: number): this
  • Restricts the currently constructed XPath expression to elements which have the passed index (starting at 1).

    The passed index defines an element's index of occurrence across all "levels/depths" of the DOM.

    Parameters

    • index: number

      an element's index of occurrence on a all "levels/depths" of the DOM - STARTS AT 1

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

levelIndex

  • levelIndex(levelIndex: number): this
  • Restricts the currently constructed XPath expression to elements which have the passed level index (starting at 1).

    The passed level index defines an element's index of occurrence on a single "level" of the DOM. Eg.: If index === 3, there must be 3 siblings on the same DOM level that match the current selector and the third one will be selected.

    Parameters

    • levelIndex: number

      an element's index of occurrence on a single "level" of the DOM - STARTS AT 1

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

name

  • name(name?: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'name'.

    Optionally, if also passing a name, the currently constructed XPath expression is further restricted to elements which have an HTML 'name' attribute with a value that equals the passed name.

    Parameters

    • Optional name: string

      a name which must equal the value of the HTML 'name' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

nameContains

  • nameContains(name: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'name' with a value that contains the passed name.

    Parameters

    • name: string

      a name which must be contained by the value of the HTML 'name' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notAttribute

  • notAttribute(name: string, value?: string): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute whose name equals the passed name.

    Optionally, if also passing a value, the currently constructed XPath expression is restricted to elements which have an HTML attribute whose name equals the passed name and whose value does not equal the passed value.

    Parameters

    • name: string

      the name of the HTML attribute used to restrict the currently constructed XPath expression

    • Optional value: string

      a value that must not equal the value of the HTML attribute with the passed name

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notAttributeContains

  • notAttributeContains(name: string, value: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute whose name does not contain the passed name.

    Optionally, if also passing a value, the currently constructed XPath expression is restricted to elements which have an HTML attribute whose name equals the passed name and whose value does not contain the passed value.

    Parameters

    • name: string

      the name of the HTML attribute used to restrict the currently constructed XPath expression

    • value: string

      a value that must not be contained by the value of the HTML attribute with the passed name

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notChecked

  • notChecked(): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'checked'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notClass

  • notClass(className?: string): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'class'.

    Optionally, if also passing a class name, the currently constructed XPath expression is restricted to elements which have an HTML 'class' attribute with a value that does not equal the passed class name.

    Parameters

    • Optional className: string

      a class name which must not equal the value of the HTML 'class' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notClassContains

  • notClassContains(className: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'class' with a value that does not contain the passed class name.

    Parameters

    • className: string

      a class name which must not be contained by the value of the HTML 'class' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notDisabled

  • notDisabled(): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'disabled'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notId

  • notId(id?: string): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'id'.

    Optionally, if also passing an id, the currently constructed XPath expression is restricted to elements which have an HTML 'id' attribute with a value that does not equal the passed id.

    Parameters

    • Optional id: string

      an id which must not equal the value of the HTML 'id' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notIdContains

  • notIdContains(id: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'id' with a value that does not contain the passed id.

    Parameters

    • id: string

      an id which must not be contained by the value of the HTML 'id' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notName

  • notName(name?: string): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'name'.

    Optionally, if also passing a name, the currently constructed XPath expression is restricted to elements which have an HTML 'name' attribute with a value that does not equal the passed name.

    Parameters

    • Optional name: string

      a name which must not equal the value of the HTML 'name' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notNameContains

  • notNameContains(name: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'name' with a value that does not contain the passed name.

    Parameters

    • name: string

      a name which must not be contained by the value of the HTML 'name' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notSelected

  • notSelected(): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'selected'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notText

  • notText(text: string): this
  • Restricts the currently constructed XPath expression to elements whose text does not equal the passed text.

    Parameters

    • text: string

      a text which must not equal the text of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notTextContains

  • notTextContains(text: string): this
  • Restricts the currently constructed XPath expression to elements whose text does not contain the passed text.

    Parameters

    • text: string

      a text which must not be contained by the text of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notType

  • notType(type?: string): this
  • Restricts the currently constructed XPath expression to elements which do not have an HTML attribute called 'type'.

    Optionally, if also passing a type, the currently constructed XPath expression is restricted to elements which have an HTML 'type' attribute with a value that does not equal the passed type.

    Parameters

    • Optional type: string

      a type which must not equal the value of the HTML 'type' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

notTypeContains

  • notTypeContains(type: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'type' with a value does not contain the passed type.

    Parameters

    • type: string

      a type which must not be contained by the value of the HTML 'type' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

reset

  • reset(selector: string): this
  • Resets the currently processed XPath expression to the passed initial XPath selector.

    This initial XPath selector must select an HTML tag that is one of the following:

    • a direct child (eg. '/span') of either another XPath expression or of the DOM root node
    • an indirect/deeply nested child (eg. '//div') of either another XPath expression or of the DOM root node

    Parameters

    • selector: string

      an XPath selector used as the initial "root" for a new XPath expression (eg. '//div')

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

selected

  • selected(): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'selected'.

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

text

  • text(text: string): this
  • Restricts the currently constructed XPath expression to elements whose text equals the passed text.

    Parameters

    • text: string

      a text which must equal the text of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

textContains

  • textContains(text: string): this
  • Restricts the currently constructed XPath expression to elements whose text contains the passed text.

    Parameters

    • text: string

      a text which must be contained by the text of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

type

  • type(type?: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'type'.

    Optionally, if also passing a type, the currently constructed XPath expression is further restricted to elements which have an HTML 'type' attribute with a value that equals the passed type.

    Parameters

    • Optional type: string

      a type which must equal the value of the HTML 'type' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

typeContains

  • typeContains(type: string): this
  • Restricts the currently constructed XPath expression to elements which have an HTML attribute called 'type' with a value that contains the passed type.

    Parameters

    • type: string

      a type which must be contained by the value of the HTML 'type' attribute of elements selected by the currently constructed XPath expression

    Returns this

    the singleton instance of XPathBuilder storing the currently constructed XPath expression

Static getInstance

Generated using TypeDoc