Skip to content

Elements

FastRPA is xpath-oriented!

FastRPA is totally based on xpath locations. It means that does not exists any way, but xpath, to access elements from the web pages. This is a important concept that guarants the consistence on framework's code base.

If you want to obtain elements using another identifier, just write an xpath that wraps that identifier. For example, if you want to get a div with an id my_div, just use the xpath //*[@id="my_div"]. You can use a site like xpather.com to help you building your xpaths.

Get elements from the page

To start our interactions with page elements, we just need to obtain these with the methods shown below.

Get just one element or the first found

web.element('//*[@id="my_div"]')
Output
<fastrpa.core.elements.Element at 0x...>

The wait strategy

By default, FastRPA always waits until the element is interactable. The default timeout is 15 seconds, and it is configurable by the FastRPA constructor. In case of timeout, you will receive a ElementTimeoutException.

1
2
3
4
5
app = FastRPA(timeout=60)
web = app.browse('https:...')

# If after the timeout, the element isn't avaliable
web.element('//*[@id="my_div"]')
Output
Traceback (most recent call last):
    ...
ElementTimeoutException: Element [//*[@id="my_div"]] not found after 60 seconds!

Disabling the waiting

If you don't want to wait, just send a wait=False parameter to the element method.

web.elements('//*[@id="my_div"]', wait=False)
Output
<fastrpa.core.elements.Element at 0x...>

If you try to get an element that is not in the page, you will get an ElementNotFoundException.

web.elements('//*[@id="my_div"]', wait=False)
Output
Traceback (most recent call last):
    ...
ElementNotFoundException: No one element [//*[@id="my_div"]] was found!

Get all elements found

web.elements('//*[@id="my_div"]')
Output
[<fastrpa.core.elements.Element at 0x...>,
 <fastrpa.core.elements.Element at 0x...>]

In the case of trying to get many elements, the framework will now run a wait strategy.

web.elements('//*[@id="my_inexistent_div"]')
Output
Traceback (most recent call last):
    ...
ElementNotFoundException: No one element [//*[@id="my_div"]] was found!

Elements abstractions

There is some abstractions that implements actions and rules for specific elements. They is listed below.

Class HTML5 tags
Element any element
InputElement input, textarea
FileInputElement input type="file"
RadioInputElement input type="radio"
CheckboxElement input type="checkbox"
SelectElement select
ListElement ol, ul
ButtonElement button, a
FormElement form
TableElement table
ImageElement img

Element reference

To interact with generical Element instances, you can use the properties and methods below.

Get the element

element = web.element('//*[id="myElement"]')
type(element)
Output
fastrpa.core.elements.Element

Get the tag

element.tag
Output
'div'

Get the id

element.id
Output
'searchform'

Get the classes

element.css_class
Output
['form', 'form-styled']

Get the inline css

element.css_inline
Output
{'background-image': 'url("...")'}

Get the text or value

element.text
Output
'Fazer login'

Returns if the element is visible for the user

element.is_visible
Output
True

Returns the value for any element attribute, or None if doesn't exists

element.attribute('data-property')
Output
'any value'

Check if some attribute has some value

element.check('attribute', 'value')
Output
False

Scroll and move the cursor to the element

element.focus()