Improve xpath
This commit is contained in:
parent
657ff90fd1
commit
5badb60ca2
48
xpath.md
48
xpath.md
|
@ -127,21 +127,6 @@ You can use nodes inside predicates.
|
||||||
//ul[li]
|
//ul[li]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Nesting predicates
|
|
||||||
This returns `<section>` if it has an `<h1>` descendant with `id='hi'`.
|
|
||||||
|
|
||||||
```
|
|
||||||
//section[//h1[@id='hi']]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Predicate order
|
|
||||||
Order is significant, these two are different.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
a[1][@href='/']
|
|
||||||
a[@href='/'][1]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Indexing
|
### Indexing
|
||||||
Use `[]` with a number, or `last()` or `position()`.
|
Use `[]` with a number, or `last()` or `position()`.
|
||||||
|
|
||||||
|
@ -152,25 +137,47 @@ Use `[]` with a number, or `last()` or `position()`.
|
||||||
//ol/li[position()=2] # ...same as above
|
//ol/li[position()=2] # ...same as above
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Predicate order
|
||||||
|
Order is significant, these two are different.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
a[1][@href='/']
|
||||||
|
a[@href='/'][1]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Nesting predicates
|
||||||
|
This returns `<section>` if it has an `<h1>` descendant with `id='hi'`.
|
||||||
|
|
||||||
|
```
|
||||||
|
//section[//h1[@id='hi']]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
### Node functions
|
### Node functions
|
||||||
|
|
||||||
text() # button[text()="Submit"]
|
```sh
|
||||||
name() # *[name()='div']
|
name() # //[starts-with(name(), 'h')]
|
||||||
|
text() # //button[text()="Submit"]
|
||||||
|
# //button/text()
|
||||||
lang(str)
|
lang(str)
|
||||||
namespace-uri()
|
namespace-uri()
|
||||||
|
|
||||||
count() # table[count(tr)=1]
|
count() # //table[count(tr)=1]
|
||||||
position() # ol/li[position()=2]
|
position() # //ol/li[position()=2]
|
||||||
|
```
|
||||||
|
|
||||||
### Boolean functions
|
### Boolean functions
|
||||||
|
|
||||||
|
```sh
|
||||||
not(expr) # button[not(text()="Submit")]
|
not(expr) # button[not(text()="Submit")]
|
||||||
|
```
|
||||||
|
|
||||||
### String functions
|
### String functions
|
||||||
|
|
||||||
|
```sh
|
||||||
contains() # font[contains(@class,"head")]
|
contains() # font[contains(@class,"head")]
|
||||||
starts-with() # font[starts-with(@class,"head")]
|
starts-with() # font[starts-with(@class,"head")]
|
||||||
ends-with() # font[ends-with(@class,"head")]
|
ends-with() # font[ends-with(@class,"head")]
|
||||||
|
@ -182,12 +189,15 @@ Functions
|
||||||
translate()
|
translate()
|
||||||
normalize-space()
|
normalize-space()
|
||||||
string-length()
|
string-length()
|
||||||
|
```
|
||||||
|
|
||||||
### Type conversion
|
### Type conversion
|
||||||
|
|
||||||
|
```sh
|
||||||
string()
|
string()
|
||||||
number()
|
number()
|
||||||
boolean()
|
boolean()
|
||||||
|
```
|
||||||
|
|
||||||
Axes
|
Axes
|
||||||
----
|
----
|
||||||
|
|
Loading…
Reference in New Issue