Action
crawlipt包含了一些内置的action,以便你更好地与网页进行交互。同时你也可以添加自己的action方法,进行扩展。
内置的action方法
所有的脚本方法(或别名)会自动映射到执行函数,所有的参数都是一一对应的,所有的WebElement元素均通过xpath进行定位。
click
None
xpath : str
None
点击某个可点击的按钮
clickMulti
click.multi
xpath : str
cnt : str
None
对某个可点击的按钮点击多次
clickByJs
click.js
xpath : str
None
通过js去点击某个按钮,这种方式可以避开遮罩层影响。但在某些禁用外部js的网站可能会失效
clickAll
click.all
xpath: str
None
点击所有可点击的选中元素
clickAllByJs
click.all.js
xpath: str
None
通过js点击所有可点击的选中元素
enter
None
xpath : str
None
在输入框键入回车
input
None
xpath : str
text : str
None
在输入框输入内容
switchLastTab
switch.tab.last
None
None
切换到最后一个窗口
switchTab
switch.tab
index : int
None
切换到第index个窗口
switchToFrame
switch.frame
xpath : str
None
进入到某个frame中
switchOutFrame
switch.frame.out
None
None
退出frame
searchRedirect
redirect.search
url : str
keyword : str
None
使用keyword替换链接中的%s进行重定向
redirect
None
url : str
None
重定向
redirectNewTab
redirect.new
url : str
None
重定向到新窗口
selectByText
select.text
xpath : str
text : str
None
通过文本对下拉选择器选择
selectByValue
select.value
xpath : str
value : str
None
通过值对下拉选择器选择
selectByIndex
select.index
xpath : str
index : int
None
通过index索引对下拉选择器选择
slide
None
xpath : str
position : list-list([x,y])
None
按住某个对象,滑动到相对于这个对象的(x,y)坐标
scrollByJs
scroll.js
height: str | int
None
通过执行js代码来实现滚动height高度(为负数则向上滚动)
scrollToBottom
scroll.bottom
None
None
通过js直接滚动到底部
scrollToTop
scroll.top
None
None
通过js直接滚动到顶部
scrollBySpace
scroll.space
cnt: str
int,
frequency: int = 0.1
通过空格实现向下滚动
scrollUpByArrow
scroll.arrow.up
cnt: str | int, frequency: float = 0.1
None
通过上箭头按键实现向上滚动
scrollDownByArrow
scroll.arrow.down
cnt: str | int, frequency: float = 0.1
None
通过下箭头按键实现向下滚动
alert
None
operation: str option in ["dismiss", "accept"],
text: str = "
None
操作浏览器弹出的alert,并返回alert的内容
getInnerText
get.innerText
xpath : str
str
获取元素的内部文本,如果元素不可见将获取不到
getTextContent
get.textContent
xpath : str
str
获取元素的内部文本
getAttribute
get.attribute
xpath : str
name : str
str
获取元素的某个属性
close
window.close
None
None
关闭当前窗口
back
window.back
None
None
在浏览器历史记录中后退一步
forward
window.forward
None
None
在浏览器历史记录中前进一步
url
window.url
None
str
获取当前窗口的url,并返回
clear
window.clear
None
None
清空所有操作状态
html
window.html
None
str
返回当前driver的page_source
log
None
msg: Any
None
在终端打印msg信息
interval
None
num: str | int
None
显式等待num秒时间
intervalRandom
interval.random
num: str | int
None
显式等待[num/2, num]秒时间
execute
None
js: str
Any
执行js code
添加你自己的action
在你添加自己的action方法前,建议你先学习一下selenium的基本使用
参考下面的示例来添加你自己的action
最后更新于