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. |
Example
1 2 3 4 5 6 7 8 9 10 | |
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:
browser.tool.execute_script("alert('Hello world!')")
With WebElement:
1 2 | |
For example, how to scroll to the first link on a page:
1 2 3 4 5 6 | |
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:
1 2 3 4 5 6 7 8 9 | |
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:
1 2 3 4 5 6 7 8 | |
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:
1 2 3 4 5 6 7 8 9 | |