如何从下面的下拉列表中选择选项。我试过xpath 或id但它不起作用。
java.util.List<WebElement> option = getDriver().findElements(By.xpath("//*[@id='ctl00_ContentOne_engage_admin_page_user_engage_admin_user_ddlUserType_listbox']"));
for(WebElement select : option){
if("Administrator".equals(select.getText()));
select.click();
}
<ul unselectable="on" class="k-list k-reset" tabindex="-1" role="listbox" aria-hidden="true" id="ctl00_ContentOne_engage_admin_page_user_engage_admin_user_ddlUserType_listbox" aria-live="off" style="overflow: auto; height: auto;">
<li tabindex="-1" role="option" unselectable="on" class="k-item k-state-selected k-state-focused" id="ctl00_ContentOne_engage_admin_page_user_engage_admin_user_ddlUserType_option_selected" aria-selected="true">Enter User Type...</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">AdminOne</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">Read Only</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">REST API</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">Publisher</li>
<li tabindex="-1" role="option" unselectable="on" class="k-item">API User</li>
</ul>
答案 0 :(得分:0)
您拥有它的方式,您似乎正在制作<ul>
元素的列表,这些元素只是一个元素。我假设您要使用以下代码列出<li>
元素列表
java.util.List<WebElement> option = getDriver().findElements(By.xpath("//li[contains(@class, 'k-item')]"));