java - 使用 selenium webdriver 找不到下拉列表元素

标签 java selenium-webdriver contains

我在使用 ID 选择下拉列表时遇到问题,因为它是动态的。

ID中有固定部分,所以我尝试使用contains,但我似乎无法掌握它的窍门。

我使用 selenium webdriver java 的代码部分:

Select dropdown = new Select (driver.findElement(By.xpath("//select[contains(@id,'_listSelect')]")));

使用 firebug 的下拉 HTML(选择部分):

<div id="00B70000008WMdr_topNav" class="topNav primaryPalette">
    <div class="controls">
        <img class="pageTitleIcon" title="Case" alt="Case" src="/img/s.gif">
        <select id="00B70000008WMdr_listSelect" class="title" title="View:" onchange="ListViewport.instances['00B70000008WMdr'].showFeedOrListView(this.options[this.selectedIndex].value)" name="fcf">
           ...
        </select>
    </div>
</div>

最佳答案

试试这个:

Select dropdown = new Select (driver.findElement(By.css("select[id$='_listSelect']")))

关于java - 使用 selenium webdriver 找不到下拉列表元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49814814/

相关文章:

java - 如何使用 Java 从文本框 Webdriver 获取类值

java - 以编程方式设置 Selenium 代理

java - Java 中使用 contains 不匹配字符串

Python Selenium Safari,禁用日志记录

arrays - 在 Swift 中使用值数组按属性过滤对象数组

java - 在多维 ArrayList 中查找字符串

java - java 遍历文件系统

java - 使用 BufferedReader 和 ScheduledExecutor 记录日志

java - 可调整角度

java - 如何在 Harmony 应用程序开发中动态更改对话框中设置的动画组件的大小?