Appium driver.find_element() reutrn dict 而不是 webelement

2023-12-27

EV:APPIUM 1.4.16 ||节点-v 12.13.1 || jdk -v 1.8.0_201 || Android SDK 25.2.5 || Python 3.8.0

我想找到该元素,但该函数返回字典类型。并抛出 AttributeError: 'dict' object has no attribute 'click'

这是代码

import time
from appium.webdriver.common.appiumby import By
from appium import webdriver

desired_caps = {
    'platformName': 'Android',
    'platformVersion': '5.1.1',
    'deviceName': '127.0.0.1:62025',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings'}

Good = driver.find_element(By.ID, "com.android.settings:id/search")
print(Good)
Good.click()
driver.quit()

好的是 {'ELEMENT': '1'}

以下是appium上显示的返回信息

info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"0249d821-45e5-4ff6-acea-ed7cb2fcfa5a"}

这是正常的吗?如果是这样,我应该如何点击该元素?

> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe -s 127.0.0.1:62025 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.settings -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Waking up device if it's not alive
> info: [debug] Pushing command to appium work queue: ["wake",{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: wake
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "dumpsys window"
> info: [debug] Screen already unlocked, continuing.
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data"}
> info: [debug] dataDir set to: /data
> info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
> info: [debug] Getting device API level
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "getprop ro.build.version.sdk"
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
> info: [debug] Device is at API Level 22
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.android.settings/.Settings"
> info: [debug] Waiting for pkg "com.android.settings" and activity ".Settings" to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "dumpsys window windows"
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "getprop ro.build.version.release"
> info: [debug] Device is at release version 5.1.1
> info: [debug] Device launched! Ready for commands
> info: [debug] Setting command timeout to the default of 60 secs
> info: [debug] Appium session started with sessionId 9d33259b-f292-4932-a393-b89182642782
> info: <-- POST /wd/hub/session 303 3757.004 ms - 74 
> info: --> GET /wd/hub/session/9d33259b-f292-4932-a393-b89182642782 {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:platformVersion":"5.1.1","appium:deviceName":"127.0.0.1:62025","appium:appPackage":"com.android.settings","appium:appActivity":".Settings"},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","platformVersion":"5.1.1","deviceName":"127.0.0.1:62025","appPackage":"com.android.settings","appActivity":".Settings"}}
> info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.1.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","platformVersion":"5.1.1","deviceName":"127.0.0.1:62025","appPackage":"com.android.settings","appActivity":".Settings"},"platformName":"Android","deviceName":"127.0.0.1:62025","appPackage":"com.android.settings","appActivity":".Settings"},"sessionId":"9d33259b-f292-4932-a393-b89182642782"}
> info: <-- GET /wd/hub/session/9d33259b-f292-4932-a393-b89182642782 200 0.543 ms - 591 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"5.1.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","platformVersion":"5.1.1","deviceName":"127.0.0.1:62025","appPackage":"com.android.settings","appActivity":".Settings"},"platformName":"Android","deviceName":"127.0.0.1:62025","appPackage":"com.android.settings","appActivity":".Settings"},"sessionId":"9d33259b-f292-4932-a393-b89182642782"}
> info: --> POST /wd/hub/session/9d33259b-f292-4932-a393-b89182642782/elements {"using":"id","value":"com.android.settings:id/search"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.android.settings:id/search","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.settings:id/search","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding com.android.settings:id/search using ID with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.android.settings:id/search]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.android.settings:id/search]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.android.settings:id/search]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=com.android.settings:id/search]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":[{"ELEMENT":"1"}]}
> info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"1"}],"sessionId":"9d33259b-f292-4932-a393-b89182642782"}
> info: <-- POST /wd/hub/session/9d33259b-f292-4932-a393-b89182642782/elements 200 171.005 ms - 89 {"status":0,"value":[{"ELEMENT":"1"}],"sessionId":"9d33259b-f292-4932-a393-b89182642782"}
> info: --> DELETE /wd/hub/session/9d33259b-f292-4932-a393-b89182642782 {}
> info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: "E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s 127.0.0.1:62025 shell "input keyevent 3"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 7.165
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] UiAutomator shut down normally
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"9d33259b-f292-4932-a393-b89182642782"}
> info: <-- DELETE /wd/hub/session/9d33259b-f292-4932-a393-b89182642782 200 612.295 ms - 76 {"status":0,"value":null,"sessionId":"9d33259b-f292-4932-a393-b89182642782"}

任何帮助,将不胜感激。


现在我已经通过升级appium版本解决了这个问题

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Appium driver.find_element() reutrn dict 而不是 webelement 的相关文章

随机推荐