gpt4 book ai didi

java - 如何使用 selenium webdriver 查找将返回下拉列表的所有值的 xpath

转载 作者:行者123 更新时间:2023-12-01 16:54:38 29 4
gpt4 key购买 nike

在我的 HTML 代码中没有选择选项的标签,但如果选择下拉菜单,则单击它会在 HTML 代码上显示下拉项目的名称

enter image description here

     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')]

关于java - 如何使用 selenium webdriver 查找将返回下拉列表的所有值的 xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61611318/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com