Condition

crawlipt包含了一些内置的condition,以便你在与网页进行交互可以进行一些逻辑判断。同时你也可以添加自己的condition方法,进行扩展。

内置的condition方法

与action方法不同,condition方法的返回值均为bool类型,你可以在whileifcheck中使用它。

方法
别名
参数
备注

presence_of_element_located

presence

xpath: str,

wait: float = 1(最长等待xpath对应元素出现时间)

判断xpath对应单个元素是否在wait时间内出现在dom结构中

presence_of_all_elements_located

presences

xpath: str,

wait: float = 1

判断xpath对应所有元素是否在wait时间内出现在dom结构中

visibility_of_element_located

visibility

xpath: str,

wait: float = 1

判断xpath对应单个元素是否在wait时间内出现在dom结构中,并且宽和高均不为0

invisibility_of_element_located

invisibility

xpath: str,

wait: float = 1

判断xpath对应单个元素是否在wait时间内出现在dom结构中,并且宽和高均为0

frame_to_be_available_and_switch_to_it

None

xpath: str,

wait: float = 1

判断xpath对应的frame是否能在wait时间内被切入

element_to_be_clickable

clickable

xpath: str,

wait: float = 1

判断xpath对应的单个元素是否能在wait时间内被点击

element_located_to_be_selected

selected

xpath: str,

wait: float = 1

判断xpath对应的单个元素是否能在wait时间内被选择

text_to_be_present_in_element

None

xpath: str,

text: str,

wait: float = 1

判断xpath对应的单个元素是否能在wait时间内出现text文本内容

text_to_be_present_in_element_value

None

xpath: str,

value: str,

wait: float = 1

判断xpath对应的单个元素的value中是否能在wait时间内出现value文本内容

alert_is_present

None

wait: float = 1

判断是否有alert弹出

fail_script关键词

在condition中如果含有fail_script关键词,则在condition失败后会执行该脚本

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

逻辑取反

使用__not-{your condition}__指令可以对condition结果进行取反

添加你自己的condition

在你添加自己的action方法前,建议你先学习一下selenium的基本使用

请参考下面的示例

最后更新于