尝试自动执行移动应用程序时程序被挂起

时间:2019-04-08 10:41:34

标签: android selenium appium

下面的程序在尝试查找元素后完全挂起。 xpath看起来也没有任何问题。我需要每次手动终止程序。我需要更改任何代码还是需要添加一些内容?

public class Test123 {
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
         DesiredCapabilities capabilities = new DesiredCapabilities();
          capabilities.setCapability("noReset", "true");
          capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
          capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
          capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.1.0");
          capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android");
          capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
          capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.talentpace.substk");
          capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.talentpace.substk.MainActivity");

          URL url=new URL("http://127.0.0.1:4723/wd/hub");
          AndroidDriver driver=new AndroidDriver(url,capabilities);
          Thread.sleep(5000);
          driver.findElementByXPath("//node[@class='android.widget.EditText']").click();
    }
}

2 个答案:

答案 0 :(得分:0)

似乎您输入了错误的xpath

正确的应该是这样

//android.widget.EditText[@class='Enter Class name here..']

答案 1 :(得分:0)

将所需功能中的 AUTOMATION_NAME Appium 更改为 uiautomator2

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");