129 lines
2.2 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.

参考 selenium 的`ActionChains`,本库也提供了自己的`ActionChains`。语法更简洁易用,每个动作执行即生效,无须`perform()`
# ✔ 创建对象
## 📍 `ActionChains`
创建动作链对象非常简单,只要把`WebPage`对象或`ChromiumPage`对象传入即可。动作链只在这个页面上生效。
**参数:**
- `page``WebPage`对象或`ChromiumPage`对象
```python
# 创建前先导入
from DrissionPage import WebPage, ActionChains
page = WebPage()
ac = ActionChains(page)
```
# ✔ 移动鼠标
## 📍 `move_to()`
此方法用于移动鼠标到元素中点,或页面上的某个绝对坐标。可设置偏移量,当带偏移量时,偏移量相对于元素左上角坐标。
**参数:**
- `ele_or_loc`:元素对象或绝对坐标,坐标为`tuple`(int, int) 形式
- `offset_x`:偏移量 x
- `offset_y`:偏移量 y
**返回:**`ActionChains`对象自己
```python
ele = page('tag:a')
ac.move_to(ele_or_loc=ele) # 使鼠标移动过到 ele 元素上
```
## 📍 `move()`
此方法用于使鼠标相对当前位置移动若干距离。
**参数:**
- `offset_x`:偏移量 x
- `offset_y`:偏移量 y
**返回:**`ActionChains`对象自己
```python
ac.move(300, 0) # 鼠标向右移动 300 像素
```
## 📍 `up()`
此方法用于使鼠标相对当前位置向上移动若干距离。
**参数:**
- `pixel`:移动距离
**返回:**`ActionChains`对象自己
```python
ac.up(50) # 鼠标向上移动 50 像素
```
## 📍 `down()`
此方法用于使鼠标相对当前位置向下移动若干距离。
**参数:**
- `pixel`:移动距离
**返回:**`ActionChains`对象自己
## 📍 `left()`
此方法用于使鼠标相对当前位置向左移动若干距离。
**参数:**
- `pixel`:移动距离
**返回:**`ActionChains`对象自己
## 📍 `right()`
此方法用于使鼠标相对当前位置向右移动若干距离。
**参数:**
- `pixel`:移动距离
**返回:**`ActionChains`对象自己
# ✔ 点击鼠标
## 📍 `click()`
## 📍 `r_click()`
## 📍 `hold()`
## 📍 `release()`
# ✔ 滚动滚轮
## 📍 `scroll()`
# ✔ 键盘按键
## 📍 `key_down()`
## 📍 `key_up()`
# ✔ 等待
## 📍 `wait()`
# ✔ 链式操作