Condition

Crawlipt includes some built-in conditions so that you can make logical judgments when interacting with web pages. At the same time, you can also add your own condition method for extension.

Built-in condition method

Unlike the action method, the return value of the condition method is of type bool, which you can use in while, if, and check.

method
alias
parms
notes

presence_of_element_located

presence

xpath: str,

wait: float = 1(The longest waiting time for the appearance of the corresponding element in xpath)

Determine whether a single element corresponding to xpath appears in the dom structure within the wait time

presence_of_all_elements_located

presences

xpath: str,

wait: float = 1

Determine whether all elements corresponding to xpath appear in the dom structure within the wait time

visibility_of_element_located

visibility

xpath: str,

wait: float = 1

Determine whether a single element corresponding to xpath appears in the dom structure within the wait time, and whether the width and height are not 0

invisibility_of_element_located

invisibility

xpath: str,

wait: float = 1

Determine whether a single element corresponding to xpath appears in the dom structure within the wait time, and whether its width and height are both 0

frame_to_be_available_and_switch_to_it

None

xpath: str,

wait: float = 1

Determine whether the frame corresponding to xpath can be cut in within the wait time

element_to_be_clickable

clickable

xpath: str,

wait: float = 1

Determine whether a single element corresponding to xpath can be clicked within the wait time

element_located_to_be_selected

selected

xpath: str,

wait: float = 1

Determine whether a single element corresponding to xpath can be selected within the wait time

text_to_be_present_in_element

None

xpath: str,

text: str,

wait: float = 1

Determine whether a single element corresponding to xpath can contain text content within the wait time

text_to_be_present_in_element_value

None

xpath: str,

value: str,

wait: float = 1

Determine whether the value text content can appear within the wait time in the value of a single element corresponding to xpath

alert_is_present

None

wait: float = 1

Determine if there is an alert pop-up

'fail_script' keyword

If the condition contains the keyword 'fail script', the script will be executed after the condition fails

{
    "check": {
        "condition": "presence",
        "xpath": "//*[@id=\"main-metro\"]/ul/li[3]/a[3]",
        "fail_script": [{
            "method": "log",
            "msg": "[fail] login failed"
        }]
    }
}

Logical inversion

The use of the _not-{your condition}__ instruction can negate the condition result

Add your own conditions

Before adding your own action method, it is recommended that you first learn the basic usage of selenium

Please refer to the following example

Last updated