I am trying to automate Mobile Web, but i am not able to select a value from “Select” dropdown. This code works perfect in Appium, but not in Appium Studio.
Below is my code:
public String strAppURL="http://newtours.demoaut.com/";
public String strUsername="udayanem";
public String strPassword="V@ud@ynvu80";
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(SeeTestCapabilityType.REPORT_DIRECTORY, reportDirectory);
dc.setCapability(SeeTestCapabilityType.REPORT_FORMAT, reportFormat);
dc.setCapability(SeeTestCapabilityType.TEST_NAME, "Parabank Sample Test");
dc.setCapability(MobileCapabilityType.UDID, strDeviceName);
if(strBrowserName.equalsIgnoreCase("Chrome"))
dc.setBrowserName(MobileBrowserType.CHROMIUM);
try
{
driver = new SeeTestAndroidDriver<>(new URL("http://"+host+":"+port), dc);
} catch (MalformedURLException e)
{
e.printStackTrace();
}
driver.get(strAppURL);
System.out.println("Navigate to application URL '"+strAppURL+"'");
Thread.sleep(5000);
//SignIn into the application
driver.findElementByXPath("//input[@name='userName']").sendKeys(strUsername);
System.out.println("Enter username as '"+strUsername+"'");
driver.findElementByXPath("//input[@name='password']").sendKeys(strPassword);
System.out.println("Enter password as '"+strPassword+"'");
driver.findElementByXPath("//input[@name='login']").click();
System.out.println("Clicked on Sign In button");
//Flight Finder
driver.findElementByXPath("//input[@name='tripType' and @value='oneway']").click();
System.out.println("Selected trip type as 'One Way'");
WebElement meNoPassngers=driver.findElementByXPath("//select[@name='passCount']");
Select noPassengers=new Select(meNoPassngers);
noPassengers.selectByVisibleText("1");
System.out.println("Selected number of Passengers as '1'");
//To select also tried below code, but didnt help. When i tried this in Chrome it was shown as Radio button and didnt select and thrown an NoSuchElement error.
driver.findElementByXPath("//select[@name='passCount']").click();
Thread.sleep(2000);
driver.findElementByXPath("//option[contains(@text,'2')]").click();
Can someone look into it and suggest any work arounds.
Thanks,
Uday