Skip to content

XPath tools

To help you generate easy xpaths, FastRPA contains a submodule xpath.

Importing

from fastrpa import xpath

Specific attributes

Id contains value

xpath.id_contains('some-value')
Output
'//*[contains(@id, "some-value")]'

To generate a xpath with children elements, you can use a last child argument. All funcions below allows this argument.

xpath.id_contains('some-value', '/id/span')
Output
'//*[contains(@id, "some-value")]/id/span'

Id equals to value

xpath.id_equals('some-value')
Output
'//*[@id="some-value"]'

Class contains value

xpath.class_contains('some-value')
Output
'//*[contains(@class, "some-value")]'

Class equals to value

xpath.class_equals('some-value')
Output
'//*[@class="some-value"]'

Name contains value

xpath.name_equals('some-value')
Output
'//*[contains(@name, "some-value")]'

Name equals to value

xpath.id_equals('some-value')
Output
'//*[@name="some-value"]'

Text contains value

xpath.text_contains('some-value')
Output
'//*[contains(text(), "some-value")]'

Text equals to value

xpath.text_equals('some-value')
Output
'//*[text()="some-value"]'

Generical attributes

Tag attribute contains some value

xpath.attribute_contains('div', '@id', 'value')
Output
'//div[contains(@id, "value")]'

Tag attribute equals to some value

xpath.attribute_equals('div', '@id', 'value')
Output
'//div[@id="value"]'