单击下拉列表中的特定元素
Clicking particular element in a drop down list
你能帮我点击下拉列表中的一个项目吗?我有一个名为 prompt-wrapper 的 class,其中包含用户名。我想点击特定用户。
在下面的示例中,我只有一个用户,但列表可以有多个用户。这里我要点击"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")]
在选择项目之前,请不要忘记单击下拉菜单将其打开。
如果下拉字段中有很多值,如果需要单击下拉列表中的特定值,请使用以下代码。
//get the drop down field first via id, name, className, cssSelector etc...
WebElement propertySelectBox = browser.findElement(By.className("txtfld"));
//Use 'Select' statement
Select propertyComboBox = new Select(propertySelectBox);
// 4 means 5th Element
propertyComboBox.selectByIndex(4);
你能帮我点击下拉列表中的一个项目吗?我有一个名为 prompt-wrapper 的 class,其中包含用户名。我想点击特定用户。
在下面的示例中,我只有一个用户,但列表可以有多个用户。这里我要点击"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")]
在选择项目之前,请不要忘记单击下拉菜单将其打开。
如果下拉字段中有很多值,如果需要单击下拉列表中的特定值,请使用以下代码。
//get the drop down field first via id, name, className, cssSelector etc...
WebElement propertySelectBox = browser.findElement(By.className("txtfld"));
//Use 'Select' statement
Select propertyComboBox = new Select(propertySelectBox);
// 4 means 5th Element
propertyComboBox.selectByIndex(4);