Appium学习笔记17-手机操作API之分辨率

#获取手机分辨率,返回字典类型
driver.get_window_size()

运行结果
在这里插入图片描述

代码:

#导入库
from appium import webdriver
import time
from appium.webdriver.common.touch_action import TouchAction

desired_caps = dict()#创建字典
desired_caps['platformName'] = 'Android'#添加字典字段:手机平台(Android、iOS)
desired_caps['platformVersion'] = '5.1'#添加字典字段:系统版本号(可从手机的设置里面查看)
desired_caps['deviceName'] = 'myphone'#添加字典字段:设备名称(随便写即可)
desired_caps['appPackage'] = 'com.android.settings'#添加字典字段:要打开的app包名
desired_caps['appActivity'] = 'com.android.settings.Settings'#添加字典字段:APP的界面名
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)#调用方法,其中'http://localhost:4723/wd/hub'即为appium服务器地址

print(driver.get_window_size())#输出手机的分辨率(宽度和高度),{'width': 1080, 'height': 1920}
print(type(driver.get_window_size()))#输出分辨率的类型(字典型)<class 'dict'>
print(driver.get_window_size()["width"])#输出分辨率中的宽度值,1080
print(type(driver.get_window_size()["width"]))#输出分辨率中的宽度值的类型(int),<class 'int'>
driver.quit()#退出此次驱动连接
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值