I am trying to use driver.FindElemnts on a dropdown list to facilitate me to count elements in a dropdown. Somehow can't get the XPath working for below piece of html -
<select class="form-control form-control-lg ng-valid ng-dirty ng-touched"
id="sel-customer-name" name="sel-customer">
<!---->
<option value="1: Object"> Kerry Mitchell </option>
<option value="2: Object"> David Brown </option>
<option value="3: Object"> Aaron Chai </option>
</select>
I used this, but seems to be wrong --
var elementsDropdown = driver.FindElements(By.XPath("//*[@id='sel-customer-
name']/option[i]"));
any help is appreciated, thanks..!!
You chose the wrong attribute value: sel-adviser-type
instead of sel-customer-name
.
So try this XPath:
//*[@id='sel-customer-name']/option
Or, in a full expression
var elementsDropdown = driver.FindElements(By.XPath("//*[@id='sel-customer-name']/option"));
Both will select you the three elements option
.