0

UIAutomator - 主活动页面

Eclipse 查找元素的代码:

`

System.out.println("Context"+driver.getContext() + "Activity: " + 
     driver.currentActivity());
     //Finding element action_search
    try{

    driver.findElement(By.id("com.shopioca.shop:id/action_search")).click();}catch(Exception e){}
        try{
        driver.findElement("android.widget.TextView", "com.shopioca.shop:id/action_search").click();}catch(Exception e1){}
        try{
        driver.findElementByAccessibilityId("Find Order").click();}catch(Exception e1){}
        try{
        driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.shopioca.shop:id/action_search\")").click();}catch(Exception e1){}
        try{
        driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.shopioca.shop:id/action_search\")")).click();}catch(Exception e1){}
        try{
        driver.findElementByClassName("android.widget.TextView").click();}catch(Exception e1){}
        try{
        driver.findElementByXPath("//android.widget.TextView[contains(@resource-id,'com.shopioca.shop:id/action_search')]").click();}catch(Exception e1){}
        try{
        driver.findElementByXPath("//android.widget.TextView[contains(@condent-desc,'Find Order')]").click();}catch(Exception e1){}
        try{
        driver.findElementByXPath("//android.support.v7.widget.LinearLayoutCompat[@index='3']/android.widget.TextView[@index='0']").click();}catch(Exception e1){}
`

Appium 服务器 - 错误:

[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[contains(@resource-id,'com.shopioca.shop:id/action_search')]","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[contains(@resource-id,'com.shopioca.shop:id/action_search')]' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[contains(@resource-id,'com.shopioca.shop:id/action_search')]' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[debug] [BaseDriver] Waited for 21331 ms so far

在此页面中找不到任何元素。在主活动页面中找到并成功登陆的登录活动元素。但我在此页面中找不到任何元素。请指教,先谢谢了。

4

1 回答 1

0

安装 Appium-UiAutomator2-driver 解决了查找抽屉菜单元素的问题。

于 2018-10-25T06:52:34.650 回答