selenium - 单击下拉列表中的特定元素

标签 selenium xpath css-selectors

您能帮我单击下拉列表中的项目吗?我有一个名为提示包装的类,其中包含用户名。我想点击一个特定的用户。

在下面的示例中,我只有一个用户,但是列表可以有多个用户。在这里,我想单击“ Janice Hunt”。

<div class="prompt-wrapper" data-reactid=".0.0.3.0.$message-panel.2.2">
    <div class="prompt-item selected hover" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413">
        <div class="prompt-item-avatar" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.0">
            <img src="/bundles/neighbourlyregistration/img/avatar.png" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.0.0">
        </div>
        <span class="prompt-item-name" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.1"><strong>Janice</strong> Hunt</span>
        <span class="prompt-item-address" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.2">
        <span class="glyph  icon glyphicon-marker" data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.2.0"></span>
        <span data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.2.1">&nbsp;</span><span data-reactid=".0.0.3.0.$message-panel.2.2.1:$user_950413.2.2">Suburb</span></span>
    </div>
</div>

最佳答案

您可以通过XPath在下拉列表中找到所需的项目:

//span[@class="prompt-item-name" and strong = "Janice" and contains(., "Hunt")]


在选择项目之前,请不要忘记单击下拉菜单以将其打开。

关于selenium - 单击下拉列表中的特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29480729/

相关文章:

php - XPath:获取具有恰好两列的表

c - libxml2 + pblSet(或任何其他集)-无法比较结果

css - nth-of-type 与 nth-child

Markdown 样式表所需的 css 兄弟选择器帮助

selenium - 使用 webdriver.io 中的相同选择器计算元素

java - Xpath解析: The prefix for element is not bound

java - 如何从selenium中禁用的输入字段获取文本

jquery - 让 nth-child 在 IE8 及更低版本中工作

java - 自动化 Flash 应用程序

javascript - Selenium 中图像验证的 NullPointerException