这是代码。我想选择Michael W Baber。未显示元素的接收错误。
<div id="ext-gen1242" class="x-combo-list-inner" style="width: 324px; height: 110px;">
<div class="x-combo-list-item">Harold W Benton,15,30143</div>
<div class="x-combo-list-item x-combo-selected">Michael W Baber,20,13222</div>
<div class="x-combo-list-item">Michael Pfeifer,20,31294</div>
<div class="x-combo-list-item">Staci D Bartels,20,32703</div>
<div class="x-combo-list-item">Stanly C McAfee,20,06136</div>
</div>
答案 0 :(得分:2)
以下是选择列表项的帮助代码: 首先,您必须使用包org.openqa.selenium.support.ui.Select中的Select Class。
然后创建Select类的对象并使用它的方法来访问下拉项,访问下拉元素的方法是:
1)selectByVisibleText(Using Text of dropdown item)
2)selectByIndex(Select the option at the given index)
3)selectByValue(Select all options that have a value matching the argument. That is, when given "India" this would select an option like: <option value="India">Bar</option>)
示例代码如下:
new Select(driver.findElement(By.id("country"))).selectByVisibleText("India");
以上代码将选择&#34; India&#34;来自国家名单。
答案 1 :(得分:0)
试试这个:
显示列表后,将鼠标悬停在该项目上,然后单击
WebElement listItem = driver.findElement(By.xpath("//div[contains(text(), 'Michael W Baber')]"));
Actions action = new Actions(driver);
action.build();
action.moveToElement(listItem)
.click();
action.perform();