python uiautomator 根据坐标点击真机
时间: 2023-07-06 09:24:19 浏览: 51
在Python uiautomator中,可以使用`click()`方法根据坐标点击屏幕。
具体步骤如下:
1. 导入uiautomator库:
```python
from uiautomator import device as d
```
2. 获取当前屏幕的大小:
```python
(width, height) = d.info['displaySizeDp']
```
3. 将坐标转换为屏幕像素坐标:
```python
x = int(width * 0.5)
y = int(height * 0.5)
```
4. 使用`click()`方法点击屏幕:
```python
d.click(x, y)
```
可以根据需要修改`x`和`y`的值,来点击不同的位置。注意,`click(x, y)`方法是阻塞的,即会等待点击完成后再返回,如果需要进行连续点击,可以使用`swipe()`方法模拟滑动操作。