browser.tool#
Functions#
count_elements(xpath, timeout=None)
#
Count number of elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the elements. | required |
timeout | float | None | In seconds. Timeout to wait for element. If | None |
Returns:
Type | Description |
---|---|
int | Number of elements. |
execute_script(script, element=None)
#
Execute JavaScript, either with WebElement
or without.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script | str | JavaScript code. | required |
element | WebElement | None | If given, execute JavaScript with | None |
Returns:
Type | Description |
---|---|
Any | Return value given by the JavaScript code. |
Example
Without WebElement
:
With WebElement
:
For example, how to scroll to the first link on a page:
is_input_valid(text, regex, ignore_case=True)
#
Check if text input matches regex condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | Input text. | required |
regex | str | Condition as regular expression. | required |
ignore_case | bool | Ignore case when comparing input text to condition. | True |
Returns:
Type | Description |
---|---|
bool |
|
Example
How to prompt the user for input in the terminal and hereafter validate the value before posting the form input:
is_url_valid(url)
#
Check if input is a valid URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url | str | Input URL. | required |
Returns:
Type | Description |
---|---|
bool |
|
Example
How to prompt the user for a valid URL in the terminal:
is_xpath_valid(xpath)
#
Check if input is a valid XPath expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | Input XPath. | required |
Returns:
Type | Description |
---|---|
bool |
|
Example
How to prompt the user for a valid XPath value in the terminal: