您能帮我单击下拉列表中的项目吗?我有一个名为提示包装的类,其中包含用户名。我想点击一个特定的用户。
在下面的示例中,我只有一个用户,但是列表可以有多个用户。在这里,我想单击“ 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"> </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/