DrissionPage/docs/使用方法/元素操作.md
2021-12-10 19:02:42 +08:00

40 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

元素操作为 d 模式独有,调用以下方法会自动切换到 d 模式。
```python
element.click(by_js) # 点击元素,可选择是否用 js 方式点击
element.click_at(by_js) # 带偏移量点击本元素相对于左上角坐标。不传入x或y值时点击元素中点
element.r_click(x, y, by_js) # 右键单击
element.r_click_at(by_js) # 带偏移量右键单击本元素相对于左上角坐标。不传入x或y值时点击元素中点
element.input(vals, clear) # 输入文本或组合键,可选择输入前是否清空文本框
element.input_txt(txt, clear) # 专门用于输入文本框,可选择输入前是否清空文本框
element.run_script(js) # 对元素运行 JavaScript 脚本
element.submit() # 提交
element.clear() # 清空元素
element.screenshot(path, filename) # 对元素截图
element.set_prop(prop, value) # 设置元素property属性值
element.set_attr(attr, value) # 设置元素attribute参数值
element.remove_attr(attr) # 删除属性
element.drag(x, y, speed, shake) # 拖动元素相对距离,可设置速度和是否随机抖动
element.drag_to(ele_or_loc, speed, shake) # 拖动元素到另一个元素或某个坐标,可设置速度和是否随机抖动
element.hover() # 在元素上悬停鼠标
page.wait_ele(loc_or_ele, mode, timeout) # 等待要查找的子元素从 dom 删除、显示、隐藏
# select 功能:
element.select.is_multi # 是否多选列表
element.select.options # 返回所有列表项对象
element.select.selected_option # 返回第一个被选中的 option 元素
element.select.selected_options # 返回所有被选中的 option 元素列表
element.select(text) # 根据文本选择下拉列表项
element.select(value, 'value') # 根据 value 选择下拉列表项
element.select(index, 'index') # 根据序号选择下拉列表项
# 多选列表功能:
element.select.deselect(text) # 根据文本取消选择下拉列表项(多选列表时有效)
element.select.deselect(value, 'value') # 根据 value 取消选择下拉列表项(多选列表时有效)
element.select.deselect(index, 'index') # 根据序号取消选择下拉列表项(多选列表时有效)
# 注:当列表为多选列表时,以上的第一个参数可以接收 list 或 tuple同时选择或取消选择多个项
element.select.clear() # 清空多选列表选项
element.select.invert() # 反选多选列表选项
```