简体   繁体   English

在Android 7模拟器中使用最新的Appium无法找到元素

[英]Unable to find elements using latest Appium in Android 7 Emulator

I have written test automation scripts for Android using selenium and Appium with Java as coding language. 我已经编写了用于Android的测试自动化脚本,该脚本使用Selenium和Appium以及Java作为编码语言。 The scripts are working perfectly fine on Android 6 Emulator. 这些脚本在Android 6 Emulator上运行良好。 However, on Android 7 emulator, the driver launches the app but is unable to locate any element on the app. 但是,在Android 7模拟器上,驱动程序会启动应用程序,但无法在应用程序上找到任何元素。

Sample code: 样例代码:

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("noReset", "true");

capabilities.setCapability("deviceName", "Nexus_5_API_24_Automation");

capabilities.setCapability("platformName", "Android");

capabilities.setCapability("app","D:\\MyProject\\apk\\test-app-6.31.11.apk");

capabilities.setCapability("newCommandTimeout", 0);

try {       
     driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);   
} catch (Exception e) {     
    Assert.fail("The app launched failed.");
 }

CommonUtils.waitInSeconds(10); // Custom method with Thread.sleep() method to wait for 10 secs


driver.findElement(By.xpath("//android.widget.TextView[@text='Device']")).click();


driver.closeApp();

driver.quit();

Where android.widget.TextView is the class name, 'text' attribute contains 'Device' as a text. 其中android.widget.TextView是类名,“ text”属性包含“ Device”作为文本。

When I run this, it fails at the driver.findElement step and throws NoSuchElementException. 当我运行它时,它在driver.findElement步骤失败,并引发NoSuchElementException。

The element with text 'Device' is a tab name and is visible and is clicked on Android 6 emulator. 带有文本“设备”的元素是一个标签名称,是可见的,并在Android 6仿真器上单击。

For Android 6, I use Appium 1.4.13 GUI version. 对于Android 6,我使用Appium 1.4.13 GUI版本。

For Android 7, I use Appium version 1.6.3 non UI version. 对于Android 7,我使用Appium版本1.6.3非UI版本。

Appium client libs: java-client-4.1.2.jar Appium客户端库:java-client-4.1.2.jar

Please Note: I cannot use devices as they are not currently available in my organisation. 请注意:我无法使用设备,因为它们当前在我的组织中不可用。

I am totally clueless as to what is causing this problem. 对于导致此问题的原因,我一无所知。 Any help will be much appreciated. 任何帮助都感激不尽。 Thanks in advance! 提前致谢!

Launch Appium GUI Inspector and check if that element for sure has a text attribute. 启动Appium GUI检查器,并检查该元素是否具有文本属性。 You can use Appium 1.5 GUI with inspector by providing emulator name in GUI and launching Appium 1.6.3 in CLI (so start appium 1.6.3, open appium GUI 1.5 and click inspector), it will work if You provide path to app and other 'staff' in settings. 您可以通过在GUI中提供仿真器名称并在CLI中启动Appium 1.6.3来将Appium 1.5 GUI与检查器一起使用(因此,启动appium 1.6.3,打开appium GUI 1.5并单击检查器),如果您提供了app和其他路径,则可以使用设置中的“人员”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM