从下拉xpath定位Selenium xpath元素(FindElements)

时间:2019-02-26 22:34:13

标签: selenium xpath dropdown

我正在尝试在下拉列表上使用driver.FindElemnts,以方便我计算下拉列表中的元素。某种方式无法使XPath在下面的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>

我用了这个,但似乎是错的-

var elementsDropdown = driver.FindElements(By.XPath("//*[@id='sel-customer- 
name']/option[i]"));

感谢您的帮助,谢谢.. !!

1 个答案:

答案 0 :(得分:2)

您选择了错误的属性值:sel-adviser-type而不是sel-customer-name
因此,请尝试以下XPath:

//*[@id='sel-customer-name']/option

或者,以完整的表达方式

var elementsDropdown = driver.FindElements(By.XPath("//*[@id='sel-customer-name']/option"));

两者都会选择三个元素option