Appium:獲取Android設(shè)備的手機屏幕分辨率
-
使用Appium獲取手機屏幕分辨率
print(driver.get_window_size()) # {'width': 1080, 'height': 2135} print(type(driver.get_window_size())) # <class 'dict'> width = driver.get_window_size()['width'] # 1080 height = driver.get_window_size()['height'] # 2135
-
使用ADB命令獲取手機屏幕分辨率
- 命令:adb shell wm size
import os import re size = os.popen('adb shell wm size').read() print(size) # 'Physical size: 1080x2340\n' # 通過正則處理 print(re.findall(r'.*?: (.*?)\n', size)[0]) # '1080x2340' # 通過字符串方法處理 print(size.split(': ')[1].replace('\n', '')) # '1080x2340' # 獲取width偷线、height size = '1080x2340'.split('x') print(size) # ['1080', '2340']