gpt4 book ai didi

java - 如何使用selenium从列表框中选择项目

转载 作者:太空宇宙 更新时间:2023-11-04 11:13:09 24 4
gpt4 key购买 nike

How can i select option from below drop down list. I tried with xpath or id but it does not work.

   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>

最佳答案

按照你的方式,你似乎正在列出 <ul> 的列表。元素,这只会是一个元素。我假设您想列出 <li> 的列表您可以使用以下代码执行的元素

java.util.List<WebElement> option = getDriver().findElements(By.xpath("//li[contains(@class, 'k-item')]"));

关于java - 如何使用selenium从列表框中选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45772822/

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