在我的HTML代码中,选项没有select标记,但如果选择下拉列表,则单击它会在HTML代码上显示下拉项目的名称
在此处输入图像描述
public void user_count_list_of_client_names() throws Exception {
//Assign and Select the dropdown list element
wait.until(ExpectedConditions.visibilityOfElementLocated(drpdown));
// driver.findElement(clientsdrpdown).click();
WebElement wbelement = driver.findElement(drpdown);
List < WebElement > elements = wbelement.findElements(drpdown);
System.out.println(elements.size());
System.out.println("Total Number of item count in dropdown list = " + elements);
for (int i = 0; i < elements.size(); i++) {
System.out.println(elements.get(i).getText());
System.out.println(elements.get(i).getAttribute("value")); //Using for loop getting one by one dropdown name using value attribute.
elements.get(i).click();
}
}
因此,您的下拉字段xpath可以像一样
//input[contains(@class, 'selection-search-input')]
首先单击它,然后可以使用Contains类(如(为下拉值构建XPATH
//*[contains(@class, 'selection-search')]//*[contains(@class, 'selection-item')]