python - 无法在 appium/python 中找到元素

标签 python automation appium

我将 Python 与 Appium 结合使用,在应用程序中进行一些导航后,Appium 找不到下一个元素。我已经通过 UI automator 捕获了该元素。似乎当我更改 Activity 时找不到该元素。

澄清一下:

  1. 启动应用 - 输入凭据 -> 按发送
  2. 按更多菜单 -> 按用户个人资料 -> 按编辑用户个人资料

当我尝试执行最后一步时,出现此错误。

[W3C] Calling AppiumDriver.findElement() with args: ["id","com.idem:id/toolbarButton","a491c080-6b0e-4320-815d-edb0f60dd1c1"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 20000 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[BaseDriver] Waited for 2855 ms so far
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[BaseDriver] Waited for 5903 ms so far
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[BaseDriver] Waited for 15048 ms so far
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[BaseDriver] Waited for 18097 ms so far
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.idem:id/toolbarButton","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.idem:id/toolbarButton' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.idem:id/toolbarButton]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[W3C] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[W3C]     at AndroidDriver.callee$0$0$ (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
[W3C]     at tryCatch (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[W3C]     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[W3C]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[W3C]     at GeneratorFunctionPrototype.invoke (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[W3C]     at run (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\webpack:\~\babel-polyfill\~\core-js\modules\es6.promise.js:75:1)
[W3C]     at C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\webpack:\~\babel-polyfill\~\core-js\modules\es6.promise.js:92:1
[W3C]     at flush (C:\Users\haka1355\AppData\Local\Programs\Appium\resources\app\webpack:\~\babel-polyfill\~\core-js\modules\_microtask.js:18:1)
[W3C]     at process._tickCallback (internal/process/next_tick.js:61:11)
[HTTP] <-- POST /wd/hub/session/a491c080-6b0e-4320-815d-edb0f60dd1c1/element 404 27246 ms - 1775
[HTTP] 
[HTTP] --> DELETE /wd/hub/session/a491c080-6b0e-4320-815d-edb0f60dd1c1
[HTTP] {}
[W3C] Calling AppiumDriver.deleteSession() with args: ["a491c080-6b0e-4320-815d-edb0f60dd1c1"]
[BaseDriver] Event 'quitSessionRequested' logged at 1548836645995 (09:24:05 GMT+0100 (W. Europe Standard Time))
[Appium] Removing session a491c080-6b0e-4320-815d-edb0f60dd1c1 from our master session list
[AndroidDriver] Shutting down Android driver
[ADB] Running 'C:\Users\haka1355\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce12171c9d44e70d04 shell am force-stop com.idem'
[ADB] Pressing the HOME button
[ADB] Running 'C:\Users\haka1355\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce12171c9d44e70d04 shell input keyevent 3'
[AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state 'stopping'
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state 'stopped'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Running 'C:\Users\haka1355\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce12171c9d44e70d04 shell ps'
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Moving to state 'stopped'
[Logcat] Stopping logcat capture
[ADB] Running 'C:\Users\haka1355\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce12171c9d44e70d04 shell am force-stop io.appium.unlock'
[AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[BaseDriver] Event 'quitSessionFinished' logged at 1548836649208 (09:24:09 GMT+0100 (W. Europe Standard Time))
[W3C] Received response: null
[W3C] But deleting session, so not returning
[W3C] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/a491c080-6b0e-4320-815d-edb0f60dd1c1 200 3217 ms - 14
[HTTP] 

任何人都可以帮助我了解可能出了什么问题吗?

最佳答案

这很明显,我不知道,也许你已经尝试过这个。使用等待?例如,尝试使用 time.sleep(5),如果测试通过,则只需为最后一个元素添加服务员。

关于python - 无法在 appium/python 中找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54438813/

相关文章:

java - 我们如何在使用 Cucumber 实现的同一场景中使用 Selenium WebDriver 和 Appium?

python - 如何使用 Boost.Python 在 Python 中调用内置函数

testing - 无法创建要在 AWS Device Farm 上上传的 jar 文件

.net - .NET 中有什么方法可以以编程方式监听 HTTP 流量吗?

java - 使用 Appium 选择随机 UIACollectionCell

java - 如何只有一个驱动程序可以用作Webdriver或Appiumdriver

python - 具有 Mechanize 的自定义身份验证处理程序

python - 删除迁移后 makemigrations 不起作用

python - 在 OSX 上使用格式语言的德语数字分隔符?

java - 您好,我面临跨浏览器测试的问题。我没有同时启动两个浏览器