Appium:在测试运行过程中未识别出元素

时间:2018-11-20 13:10:56

标签: appium appium-android

我已经使用appium inspector获得了定位器。在appium inspector中记录期间,所获得的元素效果很好。但是当我运行测试用例时,appium无法识别该元素。 下面是服务器中的日志

    [JSONWP Proxy] Proxying [POST /session] to [POST 
    http://127.0.0.1:8000/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidDeviceSerial":"3208c623a27f61e9"}}}
[Chromedriver] Webview version: 'Chrome/63.0.3239.111'
[JSONWP Proxy] Got response with status 200: {"sessionId":"a577f16ef658470ccbc8066131f27b70","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f)"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":true,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"pageLoadStrategy":"normal","platform":"ANDROID","rotatable":false,"setWindowRect":false,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"63.0.3239.111","webStorageEnabled":true}}
[Chromedriver] Changed state to 'online'
[Appium] New AndroidDriver session created successfully, session 9aa0ede8-867f-41a1-b4c9-61416598aaf0 added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1542707446213 (15:20:46 GMT+0530 (India Standard Time))
[MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"browserName":"chrome","platformName":"Android","deviceName":"3208c623a27f61e9"},"browserName":"chrome","platformName":"Android","deviceName":"3208c623a27f61e9","deviceUDID":"3208c623a27f61e9","platformVersion":"6.0.1","deviceScreenSize":"1080x1920","deviceModel":"SM-G900H","deviceManufacturer":"samsung"}
[HTTP] <-- POST /wd/hub/session 200 33062 ms - 584 
[HTTP] --> POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/url {"url":"https://www.google.com"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/url] to [POST http://127.0.0.1:8000/wd/hub/session/a577f16ef658470ccbc8066131f27b70/url] with body: {"url":"https://www.google.com"}
[JSONWP Proxy] Got response with status 200: {"sessionId":"a577f16ef658470ccbc8066131f27b70","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId a577f16ef658470ccbc8066131f27b70 with 9aa0ede8-867f-41a1-b4c9-61416598aaf0
[HTTP] <-- POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/url 200 4603 ms - 76 
[HTTP] --> POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/element {"using":"xpath","value":"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.webkit.WebView/android.view.View/android.view.View[3]/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[3]"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[JSONWP Proxy] Proxying [POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/element] to [POST http://127.0.0.1:8000/wd/hub/session/a577f16ef658470ccbc8066131f27b70/element] with body: {"using":"xpath","value":"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.webkit.WebView/android.view.View/android.view.View[3]/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[3]"}
[JSONWP Proxy] Got response with status 200: {"sessionId":"a577f16ef658470ccbc8066131f27b70","status":7,"value":{"message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout[2]/android.webkit.WebView/android.view.View/android.view.View[3]/android.view.View[1]/android.view.View/android.view.View[2]/android.view.View[3]\"}\n  (Session info: chrome=63.0.3239.111)\n  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64)"}}
[JSONWP Proxy] Replacing sessionId a577f16ef658470ccbc8066131f27b70 with 9aa0ede8-867f-41a1-b4c9-61416598aaf0
[HTTP] <-- POST /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0/element 200 205 ms - 733 
[HTTP] --> DELETE /wd/hub/session/9aa0ede8-867f-41a1-b4c9-61416598aaf0 {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["9aa0ede8-867f-41a1-b4c9-61416598aaf0"]
[BaseDriver] Event 'quitSessionRequested' logged at 1542707451117 (15:20:51 GMT+0530 (India Standard Time))
[Appium] Removing session 9aa0ede8-867f-41a1-b4c9-61416598aaf0 from our master session list
[AndroidDriver] Shutting down Android driver
[AndroidDriver] Stopping chromedriver for context CHROMIUM
[Chromedriver] Changed state to 'stopping'
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://127.0.0.1:8000/wd/hub/session/a577f16ef658470ccbc8066131f27b70] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"a577f16ef658470ccbc8066131f27b70\",\"status\":0,\"value\":null}"
[Chromedriver] Changed state to 'stopped'

1 个答案:

答案 0 :(得分:0)

我认为问题在于,当您尝试与该元素互动时,屏幕的元素不可用。如果您尝试使用隐式等待,那么它对我不起作用。

您可以使用显式等待 Thread.sleep()

  

不推荐使用Thread.sleep()。

您可以通过以下方法使用显式等待:

 <template>
  <div>
    <div class="m-background"></div>
    <Brand />
    <div class="l-container">
      <div v-for="student in getStudents"
           :key="student.id">
           <img :src='student.image'>
           <router-link class="m-btn m-btn--left m-btn__primary"
            :to="{ name: 'home' }">{{ student.name }}
           </router-link>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Brand from '../../components/Brand'

export default {
  components: {
    Brand
  },
  computed: {
    ...mapGetters(['getStudents'])
  },
  name: 'Intros'
}
</script>

<style>

</style>