首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Appium driver.find_element() reutrn dict而不是webelement

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

Stack Overflow用户
提问于 2021-12-16 06:24:00
回答 1查看 488关注 0票数 2

EV:APPIUM 1.4.16 \x#*

我想定位元素,但是函数返回字典类型。并抛出一个AttributeError:'dict‘对象没有属性'click’

这是密码

代码语言:javascript
复制
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()

Good是{'ELEMENT':'1'}

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

代码语言:javascript
复制
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"}

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

代码语言:javascript
复制
> 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"}

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-17 01:32:03

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70374696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档