问题描述
我想使用Java在Eclipse的下拉菜单中的多个选项中选择一个选项,然后为Android设备运行代码.
代码
code
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下拉列表的许多选项中选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!