我有一个无法从中选择项目的下拉列表。我可以遍历列表中的所有项目并找到我想要的项目,但 click() 没有选择该项目。
这是代码。任何人都可以帮忙吗?
driver.findElement(By.id("components-multi-select")).findElement(By.className("icon")).click();
driver.findElement(By.id("components-suggestions"));
List<WebElement> componentList = driver.findElements(By.className("aui-list-item"));
for (WebElement component : componentList){
System.out.println(component.getText());
if (component.getText().contains(newComponent)){
component.click();
break;
}
else{
System.out.println("not equal");
}
这是组件下拉列表的html代码。
<div class="field-group aui-field-componentspicker frother-control-renderer" >
<label for="components">Component/s</label>
<div class="ajs-multi-select-placeholder textarea long-field"></div>
<select class="select hidden " id="components" multiple="multiple" name="components" size="5" data-remove-null-options="true">
<option value="-1">
Unknown
</option>
<option selected="selected" title="Component 1 - A test component" value="10240">
Component 1
</option>
<option title="Component 2 - " value="10242">
Component 2
</option>
<option title="Lee 2 " value="10371">
Lee 2
</option>
<option title="Roy " value="10370">
Roy
</option>
<option title="Test Documentation " value="10241">
Test Documentation
</option>
</select>