如何从没有id的Selenium WebDriver 3中的下拉列表中选择值

时间:2018-02-02 05:26:00

标签: selenium-webdriver

如何从相应的下拉列表中选择值?

HTML

<select _ngcontent-c13="" class="s_patient_profile_input ng-pristine ng-valid ng-touched" formcontrolname="marital_status">
<option _ngcontent-c13="" value="Single">Single</option>
                                  <option _ngcontent-c13="" value="Married">Married</option></select>

<option _ngcontent-c13="" value="Single">Single</option>

<option _ngcontent-c13="" value="Married">Married</option>

enter image description here

1 个答案:

答案 0 :(得分:1)

它不需要id,只要元素是受支持的下拉选择器,您就可以使用任何查找策略。例如,这是xpath

Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));
select.deselectAll();
select.selectByVisibleText("Value1");