python - Appium 获取activity有延迟嘛?
黄舟
黄舟 2017-04-17 18:00:37
0
0
517

大家好,目前在做应用商店的自动化脚本,想做的是,在下载管理界面,监控当前正在下载的进度,如果正常下载就print下载进度,如果出现异常,则print错误,脚本片段如下

from appium import webdriver as wd #省略通用格式的代码 wbdriver = wd.Remote('http://127.0.0.1:4723/wd/hub',dc) #紧跟着的脚本是点击一个下载,然后点击下载管理界面的按钮,跳转到下载管理的activity downnumbutton = wbdriver.find_element_by_id('downPointsText') #显示 暂停、继续、重试三种下载状态的按钮 loading_text = wbdriver.find_element_by_id('loading_text') #进度条文字 while wbdriver.current_activity == '.mdcontent.usermanager.down.UserDownActivity': if downnumbutton.text == '暂停': print('正在下载,进度: ',loading_text.text,'\r',end='') if downnumbutton.text == '继续' or downnumbutton.text == '重试': print('下载出错') wbdriver.quit()

运行以上脚本,每次python都是会报错,信息如下:

File "d:haimamarketdownandinstall.py", line 37, in
print('正在下载,进度: ',loading_text.text,'r',end='')
File "C:Python35libsite-packagesseleniumwebdriverremotewebelement.py", line 69, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "C:Python35libsite-packagesseleniumwebdriverremotewebelement.py", line 456, in _execute
return self._parent.execute(command, params)
File "C:Python35libsite-packagesseleniumwebdriverremotewebdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:Python35libsite-packagesappiumwebdrivererrorhandler.py", line 29, in check_response
raise wde
File "C:Python35libsite-packagesappiumwebdrivererrorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "C:Python35libsite-packagesseleniumwebdriverremoteerrorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

查看Appium中的信息是:

info: [debug] Getting focused package and activity
info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s 3DN4C16411024563 shell "dumpsys window windows"
info: [debug] Responding to client with success: {"status":0,"value":".mdcontent.usermanager.down.UserDownActivity","sessionId":"5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f"}
info: <-- GET /wd/hub/session/5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f/appium/device/current_activity 200 75.297 ms - 118 {"status":0,"value":".mdcontent.usermanager.down.UserDownActivity","sessionId":"5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f"}
info: --> GET /wd/hub/session/5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f/element/4/text {}
info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"4"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getText
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"鏆傚仠"}
info: [debug] Responding to client with success: {"status":0,"value":"鏆傚仠","sessionId":"5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f"}
info: <-- GET /wd/hub/session/5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f/element/4/text 200 49.005 ms - 80 {"status":0,"value":"鏆傚仠","sessionId":"5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f"}
info: --> GET /wd/hub/session/5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f/element/5/text {}
info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"5"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"5"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getText
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":7,"value":"UiSelector[INSTANCE=0, RESOURCE_ID=me.haima.androidassist:id/loading_text]"}
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"UiSelector[INSTANCE=0, RESOURCE_ID=me.haima.androidassist:id/loading_text]"},"sessionId":"5827ad6c-6f80-4d81-a2ec-f46e6c6c8b7f"}

我个人分析原因是:
当下载完成后,商店会自动调用安装,因此当前的activity就不再是 .mdcontent.usermanager.down.UserDownActivity ,理论上current_activity方法应该能检测到activity变化,但是,在商店调起安装的时候,current_activity返回的结果还是 .mdcontent.usermanager.down.UserDownActivity 。所以,依然进入了while循环,此时报错,找不到
控件

请教各位大神,我分析的原因是不是对的呢?这种情况下,我应该如何做,才能实现我的目的:监控下载进度,当下载完成调起安装的activity后,能操作安装的activity谢谢

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all (0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!