yaxp


Nameyaxp JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
Summaryintuitive xpath generator
upload_time2024-04-27 12:40:58
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords xpath selenium xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # yet another xpath generator

Create an xpath with an chainable and intuitive API.

## Quickstart

Create the most simple xpath for a `div` element:

``` python
from yaxp import xpath

# //div
xpath.div
```

xpath objects are chainable:

``` python
# //div//h1
xpath.div.h1
```

Any keyword argument you pass will add a filter for an
attribute with the name and value of the keyword:

``` python
# //div[@role="cell"]
xpath.div(role="cell")
```

Alternatively, use the `by()` method to specify attributes:

``` python
# //*[@class="main"]
xpath.by(_class="main")
```

An `_` at the beginning of the attribute name will be
removed, this is helpful for attributes that represents
python keywords like "class" or "id":

``` python
# //div[@class="cell"][@id="myid"]
xpath.div(_class="cell", _id="myid")
```

If the value of an attribute starts with an asteric (`*`), the xpath matches
any element that has the following text as a substring in this attribute

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

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

``` python
# //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):

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

Nested predicates are chainable:

``` python
# //div[./span[@class='mycl'][./p[text()="hello"]]]
xpath.div.has(xpath.span(_class="mycl")).has(xpath.p(text="hello"))
```

As you can see in the example above, a text attribute will be converted to "text()".
In order to avoid this, use "_":

``` python
# //p[@text="hello"]]]
xpath.p(_text="hello"))
```

An "_" attrbute will be converted to ".":

``` python
# //p[contains(., "world")]
xpath.p(_="*world")
```

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:

``` python
# //div[contains(concat(' ', normalize-space(@class), ' '), ' myclass ')]
xpath.div(_class="#myclass")
```

Any combination of the features are allowed:

``` python
# //span[contains(@class, "mycl")][@placeholder="huhu"]
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)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "yaxp",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "xpath, selenium, xml",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/11/54/b89fa17863a86ea7fda19817ebca3344c11e9405d511b2f93d9ffabd24d8/yaxp-1.0.1.tar.gz",
    "platform": null,
    "description": "# yet another xpath generator\n\nCreate an xpath with an chainable and intuitive API.\n\n## Quickstart\n\nCreate the most simple xpath for a `div` element:\n\n``` python\nfrom yaxp import xpath\n\n# //div\nxpath.div\n```\n\nxpath objects are chainable:\n\n``` python\n# //div//h1\nxpath.div.h1\n```\n\nAny keyword argument you pass will add a filter for an\nattribute with the name and value of the keyword:\n\n``` python\n# //div[@role=\"cell\"]\nxpath.div(role=\"cell\")\n```\n\nAlternatively, use the `by()` method to specify attributes:\n\n``` python\n# //*[@class=\"main\"]\nxpath.by(_class=\"main\")\n```\n\nAn `_` at the beginning of the attribute name will be\nremoved, this is helpful for attributes that represents\npython keywords like \"class\" or \"id\":\n\n``` python\n# //div[@class=\"cell\"][@id=\"myid\"]\nxpath.div(_class=\"cell\", _id=\"myid\")\n```\n\nIf the value of an attribute starts with an asteric (`*`), the xpath matches\nany element that has the following text as a substring in this attribute\n\n``` python\n# //div[contains(@class, 'mycl')]\nxpath.div(_class=\"*mycl\")               \n```\n\nAlternatively, you can use the `contains()` function to filter for subtrings.\nthe following statement is equal to the above:\n\n``` python\n# //div[contains(@class, 'mycl')]\nxpath.div.contains(_class=\"mycl\")\n```\n\nxpath supports \"nested predicates\", i.e. you can filter for specific sub-elements,\nwhile the xpath itself will point to the parent element (div in this example):\n\n``` python\n# //div[./span[@class='mycl']]\nxpath.div.has(xpath.span(_class=\"mycl\"))\n```\n\nNested predicates are chainable:\n\n``` python\n# //div[./span[@class='mycl'][./p[text()=\"hello\"]]]\nxpath.div.has(xpath.span(_class=\"mycl\")).has(xpath.p(text=\"hello\"))\n```\n\nAs you can see in the example above, a text attribute will be converted to \"text()\".\nIn order to avoid this, use \"_\":\n\n``` python\n# //p[@text=\"hello\"]]]\nxpath.p(_text=\"hello\"))\n```\n\nAn \"_\" attrbute will be converted to \".\":\n\n``` python\n# //p[contains(., \"world\")]\nxpath.p(_=\"*world\")\n```\n\nIf the value of an attribute starts with a hashtag (`#`), the xpath matches\nany element that has the following text as a *full word* in this attribute:\n\n``` python\n# //div[contains(concat(' ', normalize-space(@class), ' '), ' myclass ')]\nxpath.div(_class=\"#myclass\")\n```\n\nAny combination of the features are allowed:\n\n``` python\n# //span[contains(@class, \"mycl\")][@placeholder=\"huhu\"]\nxpath.span(_class=\"*mycl\", _placeholder='huhu')\n```\n\nAn `_` in the role will be converted to a \".\":\n\n``` python\n# //Android.Container[@id=\"huhu\"]\nxp.Android_Container(_id=\"huhu\")\n```\n\nUse double `__` if you need an `_`:\n\n``` python\n# //Android_Container[@id=\"huhu\"]\nxp.Android__Container(_id=\"huhu\")\n```\n\n## Further reading\n\n- [The xpath cheat sheet](https://devhints.io/xpath)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "intuitive xpath generator",
    "version": "1.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/realtimeprojects/yaxp/issues",
        "Homepage": "https://github.com/realtimeprojects/yaxp"
    },
    "split_keywords": [
        "xpath",
        " selenium",
        " xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "91e0bc515d0ddeb269cd859aae4a9b0aceb63d6df58da4ad907f499ec19db842",
                "md5": "c76f27fd7a6ef439b228aeac490f3063",
                "sha256": "26d7ca70b57dd6aadc0f3a682902330ae6ffcf5c359365fe997b3c67287d9e72"
            },
            "downloads": -1,
            "filename": "yaxp-1.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c76f27fd7a6ef439b228aeac490f3063",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4072,
            "upload_time": "2024-04-27T12:40:56",
            "upload_time_iso_8601": "2024-04-27T12:40:56.338448Z",
            "url": "https://files.pythonhosted.org/packages/91/e0/bc515d0ddeb269cd859aae4a9b0aceb63d6df58da4ad907f499ec19db842/yaxp-1.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1154b89fa17863a86ea7fda19817ebca3344c11e9405d511b2f93d9ffabd24d8",
                "md5": "77432f5797f0999df06ce97489cfee20",
                "sha256": "ba853b5dc949b10abff39937df78e78336e3d88ad8b2e3b240c30dbaf15f1559"
            },
            "downloads": -1,
            "filename": "yaxp-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "77432f5797f0999df06ce97489cfee20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4650,
            "upload_time": "2024-04-27T12:40:58",
            "upload_time_iso_8601": "2024-04-27T12:40:58.393175Z",
            "url": "https://files.pythonhosted.org/packages/11/54/b89fa17863a86ea7fda19817ebca3344c11e9405d511b2f93d9ffabd24d8/yaxp-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 12:40:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "realtimeprojects",
    "github_project": "yaxp",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "yaxp"
}
        
Elapsed time: 2.22064s