Skip to main content

Editing XPaths Manually

Sequentum Enterprise will usually create an optimal selection XPath, but sometimes you may find it necessary to fine-tune the XPath manually. It can be difficult, however, to create an XPath from scratch. If you want to manually edit an XPath, we recommend that you first let Sequentum Enterprise generate the XPath and then edit it.

As we show in the figures below, you can use either the status bar XPath editor or the XPath panel to manually edit an XPath.

EditingXpathManually.png

The status bar XPath editor

ManualXpathEditor.png

The XPath panel

XPath Expressions for dynamic elements

You can use the below XPath expressions to edit and fine tune the complex XPaths and dynamic elements:

Category

Description

XPath(1.0 -2.0)

General

Whole web page

//html

Whole web page body

/html/body

All text nodes of web page

//text()

Element <E> by absolute reference

/html/body/.../.../.../E

Tags

Element <E> by relative reference

//E

Second <E> element anywhere on page

(//E)[2]

Image element

//img

Element <E> with attribute A

//E[@A]

Element <E> with attribute A containing text 't' exactly

//E[@A='t']

Element <E> with attribute A containing text 't'

//E[contains(@A,'t')]

Element <E> whose attribute A begins with 't'

//E[starts-with(@A, 't')]

Element <E> whose attribute A ends with 't'

//E[ends-with(@A, 't')] or //E[substring(@A, string-length(@A) - string-length('t')+1)='t']

Element <E> with attribute A containing word 'w'

//E[contains(concat(' ', @A, ' '), ' w ')]

Element <E> with attribute A matching regex ‘r’

//E[matches(@A, ‘r’)]

Element <E1> with id I1 or element <E2> with id I2

//E1[@id=I1] | //E2[@id=I2]

Element <E1> with id I1 or id I2

//E1[@id=I1 or @id=I2]

Attribute

 Attribute A of element <E>

//E/@A

Attribute A of any element

//*/@A

Attribute A1 of element <E> where attribute A2 is 't' exactly

//E[@A2='t']/@A1

Attribute A of element <E> where A contains 't'

//E[contains(@A,'t')]/@A

Id & Name

Element <E> with id I

//E[@id='I']

Element with id I

//*[@id='I']

Element <E> with name N

//E[@name='N']

Element with name N

//*[@name='N']

Element with id X or, failing that, a name X

//*[@id='X' or @name='X']

Element with name N & specified 0-based index ‘v’

//*[@name='N'][v+1]

Element with name N & specified value ‘v’

//*[@name='N'][@value='v']

Lang & CSS

Element <E> is explicitly in language L or subcode

//E[@lang='L' or starts-with(@lang, concat('L', '-'))]

Element with a class C

//*[contains(concat(' ', @class, ' '), ' C ')]

Class Element <E> with a class C

//E[contains(concat(' ', @class, ' '), ' C ')]

Text & Link

Element containing text 't' exactly

//*[.='t']

Element <E> containing text 't'

//E[contains(text(),'t')]

Link element

//a

<a> containing text 't' exactly

//a[.='t']

<a> containing text 't'

//a[contains(text(),'t')]

Link <a> with target link 'url'

//a[@href='url']

Link URL labeled with text 't' exactly

//a[.='t']/@href

Parent & Child

First child of element <E>

//E/*[1]

First <E> child

//E[1]

Last child of element E

//E/*[last()]

Last <E> child

//E[last()]

Second <E> child

//E[2] OR //E/following-sibling::E

Second child that is an <E> element

//*[2][name()='E']

Second-to-last <E> child

//E[last()-1]

Second-to-last child that is an <E> element

//*[last()-1][name()='E']

Element <E1> with only <E2> children

//E1/[E2 and not( *[not(self::E2)])]

Parent of element <E>

//E/..

Descendant <E> of element with id I using specific path

//*[@id='I']/ . . ./. . ./. . ./E

Descendant <E> of element with id I using unspecified path

//*[@id='I']//E

Element <E> with no children

//E[count(*)=0]

Element <E> with an only child

//E[count(*)=1]

Element <E> that is an only child

//E[count(preceding-sibling::*)+count(following-sibling::*)=0]

Element <E> with no <E> siblings

//E[count(../E) = 1]

Every Nth element starting with the (M+1)th

//E[position() mod N = M + 1]

Sibling

Element <E1> following some sibling <E2>

//E2/following-sibling::E1

Element <E1> immediately following sibling <E2>

//E2/following-sibling::*[1][name()='E1']

Element <E1> following sibling <E2> with one intermediary

//E2/following-sibling::*[2][name()='E1']

Sibling element immediately following <E>

//E/following-sibling::*

Element <E1> preceding some sibling <E2>

//E2/preceding-sibling::E1

Element <E1> immediately preceding sibling <E2>

//E2/preceding-sibling::*[1][name()='E1']

Element <E1> preceding sibling <E2> with one intermediary

//E2/preceding-sibling::*[2][name()='E1']

Sibling element immediately preceding <E>

//E/preceding-sibling::*[1]

Table

Cell by row and column (e.g. 3rd row, 2nd column)

//*[@id='TestTable']//tr[3]//td[2]

Table Cell immediately following cell containing 't' exactly

//td[preceding-sibling::td='t']

Cell immediately following cell containing 't'

//td[preceding-sibling::td[contains(.,'t')]]

Dynamic

User interface element <E> that is disabled

//E[@disabled]

User interface element that is enabled

//*[not(@disabled)]

Checkbox (or radio button) that is checked

//*[@checked]

OR & AND

Identifies the elements whose single or both conditions are true

//*[@type='submit' or @name='btnReset']

Identifies the elements whose both conditions are true. It fails to find element if any one condition is false.

//input[@type='submit' and @name='btnLogin']

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.