到模拟器中删除/data/local/tmp 该路劲下的 screenshot.png,或者赋予这个文件及所在目录所有权限,再执行脚本,截图也还是没保存到指定路径。
代码:
from time import sleep
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.4'
desired_caps['deviceName'] = '127.0.0.1:6555'
desired_caps['appPackage'] = 'cn.mailchat'
desired_caps['appActivity'] = 'cn.mailchat.activity.setup.WelcomeActivity'
dr=webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
sleep(5)
dr.get_screenshot_as_file("E:\Appium\Mailchat\image\getscreen\p3.png")
截图部分的日志:
info: <-- GET /wd/hub/session/9881277c-b170-475f-b5f6-c5a7bce45781 200 1.509 ms - 637 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"cn.mailchat.activity.setup.WelcomeActivity","platformName":"Android","appPackage":"cn.mailchat","deviceName":"127.0.0.1:6555","platformVersion":"4.4.4"},"appActivity":"cn.mailchat.activity.setup.WelcomeActivity","platformName":"Android","appPackage":"cn.mailchat","deviceName":"127.0.0.1:6555"},"sessionId":"9881277c-b170-475f-b5f6-c5a7bce45781"}
info: --> GET /wd/hub/session/9881277c-b170-475f-b5f6-c5a7bce45781/screenshot {}
info: [debug] executing cmd: D:\Monkey\SDK\sdk\platform-tools\adb.exe -s 127.0.0.1:6555 shell "/system/bin/rm /data/local/tmp/screenshot.png; /system/bin/screencap -p /data/local/tmp/screenshot.png "
info: [debug] executing cmd: D:\Monkey\SDK\sdk\platform-tools\adb.exe -s 127.0.0.1:6555 pull /data/local/tmp/screenshot.png "C:\Users\linchs\AppData\Local\Temp\appium1161016-7452-xmj3tc.png"