ken4ward
ken4ward

Reputation: 2296

Select from a dropdown in Android using Selenium and Appium

I have been having issues to select from a gender dropdown on Android using Selenium and Appium, after several trials, I created this screenshot:

enter image description here

enter image description here

enter image description here

enter image description here

How do I select a gender type from the dropdown?

Upvotes: 0

Views: 4029

Answers (1)

Alan Bueno
Alan Bueno

Reputation: 141

With javascript and wd as my driver provider, I use something like this:

let cmbBoxId = driver.waitForElementById("gender", '', timeOut, pollFreq); 
// note: Without the com.appzonegroup.dejavuandroid.zoneRevamp:id/

// Clicking the dropDown to open the listView
cmbBoxId.click();

let optionPath = "//android.widget.TextView[@resource-id='" +
        "com.appzonegroup.dejavuandroid.zoneRevamp:id/spinner_item";

// You can choose to look for the option by index or text

// By Index of the desired option
// optionPath += " and @index='" + "1" + "'";

// **OR**

// By Text of the desired option
// optionPath += " and @text='" + "Female" + "'";

optionPath += "]";

//Clicking the desired option
driver.waitForElementByXPath(optionPath, '', timeOut, pollFreq).click();

Good luck!

Upvotes: 1

Related Questions