本文介绍了为Android设备运行代码时,使用java从Eclipse下拉列表中的多个选项中选择一个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从使用 java 的 eclipse 下拉菜单中的多个选项中选择一个选项,并为 android 设备运行代码.
代码
public class Selendroid {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
// TODO Auto-generated method stub
// Create object of DesiredCapabilities class
DesiredCapabilities capabilities = new DesiredCapabilities();
// Optional
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
// Specify the device name (any name)
capabilities.setCapability("deviceName", "My New Phone");
// Platform version
capabilities.setCapability("platformVersion", "5.1");
// platform name
capabilities.setCapability("platformName", "Android");
// specify the application package that we copied from appium
capabilities.setCapability("appPackage", "com.testingqw.laborfind");
// specify the application activity that we copied from appium
capabilities.setCapability("appActivity", "com.testingqw.laborfind.Activity.SplashScreen");
// Start android driver I used 4727 port by default it will be 4723
driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);
// Specify the implicit wait of 5 second
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.findElement(By.id("com.testingqw.laborfind:id/tv_default_spinner")).click();
driver.findElement(By.name("English")).click();;
// Wait for 10 second
Thread.sleep(5000L);
推荐答案
driver.findElement(By.xpath("//android.widget.TextView[@text='Hindi']")).click();
driver.findElement(By.xpath("//class[@text='特定文本在你想点击的地方']")).click();这是上述查询的解决方案.它确实有效,因为我在两天内经过大量研发后自己找到了这个解决方案.
driver.findElement(By.xpath("//android.widget.TextView[@text='Hindi']")).click();
driver.findElement(By.xpath("//class[@text='specific text at that where you want to click ']")).click(); This is solution for the above query .its really work because i find this solution myself after alot R&D in two days.
这篇关于为Android设备运行代码时,使用java从Eclipse下拉列表中的多个选项中选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!