Appium在列表中选择条目后找不到元素?

时间:2019-04-24 18:03:44

标签: android groovy webdriver okhttp appium-android

所以我对Appium还是陌生的,我不能说我已经按照预期配置了所有东西,但是到目前为止,一切都按照目前的方式进行:)

基本上,我是在应用本身的开发人员设置中设置测试环境。 为此,我单击菜单项,在列表中选择环境,然后我要检查菜单项是否包含所需环境的名称,即使在使用相同元素之前,Appium也无法找到该元素xpath和所有。使用Appium Inspector,我可以在没有问题的情况下完成此方案,并使用与预期相同的xpath来完善该元素,但是通过WebDriver运行此方案时,它无法正常工作。

Java: 1.8.0_201
Android Emulator: 28.0.25
Android SDK Platform Tools: 28.0.2
Android SDK Tools: 26.1.1
Appium Desktop: 1.12.1

我的能力:

{
  "locale": "EN",
  "language": "en",
  "avd": "Nexus6",
  "deviceName": "Nexus6",
  "platformName": "Android",
  "platformVersion": "8.0",
  "appPackage": "de.safas.android.dab",
  "appActivity": "de.safas.main.SafasApp",
  "app": "T:/consumer-debug-p05.00.apk",
  "noReset": true,
  "skipUnlock": true,
  "noResetValue": true,
  "useJSONSource": true,
  "simpleIsVisibleCheck": true,
  "autoGrantPermissions": true,
  "newCommandTimeout": 160000,
  "automationName": "UiAutomator2"
}

有问题的代码

def driver = TestDriver.getWebDriver() as AndroidDriver
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS)

// get current selected environment (part is not included now)
final btnHostBySelector = MobileBy.xpath(".//android.widget.TextView[starts-with(@text, 'Selected host environment')]")
def btnHostWebElement = driver.findElement(btnHostBySelector)
println "text before: ${btnHostWebElement.getText()}"

// open list
btnHostWebElement.click()

// select entry
final optHostsByLocator = MobileBy.xpath(".//android.widget.CheckedTextView")
def optHostsWebElement = driver.findElements(optHostsByLocator)
optHostsWebElement.find { it.getText().equalsIgnoreCase(testEnv) }.click()
println "entry selected"

// verify selection after returning back from the list
btnHostWebElement = driver.findElement(btnHostBySelector) // <-- not working anymore
println "text after: ${btnHostWebElement.getText()}"

WebDriverException仅在测试等待连接的至少10分钟的非常长的超时之后抛出? 控制台日志:

24.04.2019 18:07:52.899 [#01] > findElement(By.xpath: .//android.widget.TextView[starts-with(@text, 'Selected host environment')])
text before: Selected host environment RESERVE2
entry selected
org.openqa.selenium.WebDriverException: java.io.IOException: unexpected end of stream on Connection{127.0.0.1:4723, proxy=DIRECT hostAddress=/127.0.0.1:4723 cipherSuite=none protocol=http/1.1}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'RYZEN5', ip: '192.168.0.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: AndroidDriver
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:254)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:152)
    at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at io.appium.java_client.MobileDriver$findElement.call(Unknown Source)
    ...

    Caused by: java.io.IOException: unexpected end of stream on Connection{127.0.0.1:4723, proxy=DIRECT hostAddress=/127.0.0.1:4723 cipherSuite=none protocol=http/1.1}
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at org.openqa.selenium.remote.internal.OkHttpClient$Factory$1.lambda$createClient$1(OkHttpClient.java:152)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
    at okhttp3.RealCall.execute(RealCall.java:77)
    at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:103)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:155)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:428)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:152)
    at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at io.appium.java_client.MobileDriver$findElement.call(Unknown Source)
  ...

Caused by: java.io.EOFException: \n not found: limit=0 content=…
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:237)
    at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
    ... 62 more
06:42:26处的

是appium日志中的10分钟延迟:

[2019-04-24 06:40:25][HTTP] --> POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/elements
[2019-04-24 06:40:25][HTTP] {"using":"xpath","value":".//android.widget.CheckedTextView"}
[2019-04-24 06:40:25][W3C (94274fbe)] Calling AppiumDriver.findElements() with args: ["xpath",".//android.widget.CheckedTextView","94274fbe-b200-42a9-8eac-baff6b0e4e60"]
[2019-04-24 06:40:25][BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[2019-04-24 06:40:25][BaseDriver] Waiting up to 5000 ms for condition
[2019-04-24 06:40:25][AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":".//android.widget.CheckedTextView","context":"","multiple":true}}
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":".//android.widget.CheckedTextView","context":"","multiple":true}}
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding './/android.widget.CheckedTextView' using 'XPATH' with the contextId: '' multiple: true
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[2019-04-24 06:40:25][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding './/android.widget.CheckedTextView' using 'XPATH' with the contextId: '' multiple: true
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=0]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=0]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=1]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=1]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=2]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=2]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=3]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=3]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=4]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=4]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=5]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=5]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=6]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=6]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=7]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=7]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=8]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[CLASS=android.widget.CheckedTextView, INSTANCE=8]
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Selector ends with instance.
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":[{"ELEMENT":"139"},{"ELEMENT":"140"},{"ELEMENT":"141"},{"ELEMENT":"142"},{"ELEMENT":"143"},{"ELEMENT":"144"},{"ELEMENT":"145"},{"ELEMENT":"146"},{"ELEMENT":"147"}]}
[2019-04-24 06:40:26][AndroidBootstrap] Received command result from bootstrap
[2019-04-24 06:40:26][W3C (94274fbe)] Responding to client with driver.findElements() result: [{"element-6066-11e4-a52e-4f735466cecf":"139","ELEMENT":"139"},{"element-6066-11e4-a52e-4f735466cecf":"140","ELEMENT":"140"},{"element-6066-11e4-a52e-4f735466cecf":"141","ELEMENT":"141"},{"element-6066-11e4-a52e-4f735466cecf":"142","ELEMENT":"142"},{"element-6066-11e4-a52e-4f735466cecf":"143","ELEMENT":"143"},{"element-6066-11e4-a52e-4f735466cecf":"144","ELEMENT":"144"},{"element-6066-11e4-a52e-4f735466cecf":"145","ELEMENT":"145"},{"element-6066-11e4-a52e-4f735466cecf":"146","ELEMENT":"146"},{"element-6066-11e4-a52e-4f735466cecf":"147","ELEMENT":"147"}]
[2019-04-24 06:40:26][HTTP] <-- POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/elements 200 888 ms - 569
[2019-04-24 06:40:26][HTTP] 
[2019-04-24 06:40:26][HTTP] --> GET /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element/139/text
[2019-04-24 06:40:26][HTTP] {}
[2019-04-24 06:40:26][W3C (94274fbe)] Calling AppiumDriver.getText() with args: ["139","94274fbe-b200-42a9-8eac-baff6b0e4e60"]
[2019-04-24 06:40:26][AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getText","params":{"elementId":"139"}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"139"}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"..."}
[2019-04-24 06:40:26][AndroidBootstrap] Received command result from bootstrap
[2019-04-24 06:40:26][W3C (94274fbe)] Responding to client with driver.getText() result: "..."
[2019-04-24 06:40:26][HTTP] <-- GET /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element/139/text 200 10 ms - 17
...
[2019-04-24 06:40:26][HTTP] 
[2019-04-24 06:40:26][HTTP] --> POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element/141/click
[2019-04-24 06:40:26][HTTP] {"id":"141"}
[2019-04-24 06:40:26][W3C (94274fbe)] Calling AppiumDriver.click() with args: ["141","94274fbe-b200-42a9-8eac-baff6b0e4e60"]
[2019-04-24 06:40:26][AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"141"}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"141"}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[2019-04-24 06:40:26][AndroidBootstrap] Received command result from bootstrap
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[2019-04-24 06:40:26][W3C (94274fbe)] Responding to client with driver.click() result: true
[2019-04-24 06:40:26][HTTP] <-- POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element/141/click 200 161 ms - 14
[2019-04-24 06:40:26][HTTP] 
[2019-04-24 06:40:26][HTTP] --> POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element
[2019-04-24 06:40:26][HTTP] {"using":"xpath","value":".//android.widget.TextView[starts-with(@text, 'Selected host environment')]"}
[2019-04-24 06:40:26][W3C (94274fbe)] Calling AppiumDriver.findElement() with args: ["xpath",".//android.widget.TextView[starts-with(@text, 'Selected host environment')]","94274fbe-b200-42a9-8eac-baff6b0e4e60"]
[2019-04-24 06:40:26][BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[2019-04-24 06:40:26][BaseDriver] Waiting up to 5000 ms for condition
[2019-04-24 06:40:26][AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":".//android.widget.TextView[starts-with(@text, 'Selected host environment')]","context":"","multiple":false}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":".//android.widget.TextView[starts-with(@text, 'Selected host environment')]","context":"","multiple":false}}
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[2019-04-24 06:40:26][AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding './/android.widget.TextView[starts-with(@text, 'Selected host environment')]' using 'XPATH' with the contextId: '' multiple: false
[2019-04-24 06:42:26][HTTP] <-- POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element - - ms - -
[2019-04-24 06:42:26][HTTP] 
[2019-04-24 06:42:26][HTTP] --> POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element
[2019-04-24 06:42:26][HTTP] {"using":"xpath","value":".//android.widget.TextView[starts-with(@text, 'Selected host environment')]"}
[2019-04-24 06:42:26][W3C (94274fbe)] Calling AppiumDriver.findElement() with args: ["xpath",".//android.widget.TextView[starts-with(@text, 'Selected host environment')]","94274fbe-b200-42a9-8eac-baff6b0e4e60"]
[2019-04-24 06:52:26][HTTP] <-- POST /wd/hub/session/94274fbe-b200-42a9-8eac-baff6b0e4e60/element - - ms - -
[2019-04-24 06:52:26][HTTP] 

图中的场景: the scenario in pictures

  1. 使用RESERVE2检查条目的名称Selected host environment
  2. 单击条目以打开所有环境的列表
  3. 选择所需的主机环境RESERVE1
  4. 使用RESERVE1验证条目的名称Selected host environment

和4.找不到该条目。甚至driver.getPageSource()都无法正常工作,并且还有10分钟超时的异常。 怎么了? :D

更新:如果我将automationName设置为UiAutomator2,似乎不会发生此问题,但是我仍然想知道我的场景中是否有东西可以这是如此片状或仅仅是Appium

0 个答案:

没有答案