Skip to content

Commit

Permalink
Update README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimeprojects committed Sep 7, 2023
1 parent 1854429 commit d927798
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ xpath.div(_class="*mycl")
```

Alternatively, you can use the `contains()` function to filter for subtrings.
the following statement is equal to the above
the following statement is equal to the above:

``` python
xpath.div.contains(_class="mycl") # //div[contains(@class, 'mycl')]
# //div[contains(@class, 'mycl')]
xpath.div.contains(_class="mycl")
```

xpath supports "nested predicates", i.e. you can filter for specific sub-elements,
while the xpath itself will point to the parent element (div in this example).
while the xpath itself will point to the parent element (div in this example):

``` python
# //div[./span[@class='mycl']]
Expand All @@ -75,7 +76,7 @@ xpath.div.has(xpath.span(_class="mycl")).has(xpath.p(text="hello"))
```

If the value of an attribute starts with a hashtag (`#`), the xpath matches
any element that has the following text as a *full word* in this attribute.
any element that has the following text as a *full word* in this attribute:

``` python
# //div[contains(concat(' ', normalize-space(@class), ' '), ' myclass ')]
Expand All @@ -89,6 +90,20 @@ Any combination of the features are allowed:
xpath.span(_class="*mycl", _placeholder='huhu')
```

An `_` in the role will be converted to a ".":

``` python
# //Android.Container[@id="huhu"]
xp.Android_Container(_id="huhu")
```

Use double `__` if you need an `_`:

``` python
# //Android_Container[@id="huhu"]
xp.Android__Container(_id="huhu")
```

## Further reading

- [The xpath cheat sheet](https://devhints.io/xpath)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = yaxp
version = 0.2.4
version = 0.2.5
description = intuitive xpath generator
keywords = xpath, selenium, xml
long_description = file: README.md
Expand Down

0 comments on commit d927798

Please sign in to comment.