py代码:
from appium import webdriver
import time
desired_caps = {}
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_capabilities=desired_caps)
time.sleep(10)
driver.close_app()
driver.quit()
运行结果及报错内容
D:\data\softwares\python\python.exe D:/data/code/appcode/1入门案例.py
Traceback (most recent call last):
File "D:\data\code\appcode\1入门案例.py", line 18, in
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_capabilities=desired_caps)
File "D:\data\softwares\python\lib\site-packages\appium\webdriver\webdriver.py", line 274, in init
super().init(
File "D:\data\softwares\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in init
self.start_session(capabilities, browser_profile)
File "D:\data\softwares\python\lib\site-packages\appium\webdriver\webdriver.py", line 369, in start_session
response = self.execute(RemoteCommand.NEW_SESSION, parameters)
File "D:\data\softwares\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
self.error_handler.check_response(response)
File "D:\data\softwares\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.
at getResponseForW3CError (C:\Users\小呆\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
at asyncHandler (C:\Users\小呆\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37)
at process._tickCallback (internal/process/next_tick.js:68:7)
Process finished with exit code 1
我想要达到的结果
用代码打开手机中的设置并停留十秒,然后关闭