我编写了以下代码,用于从下拉列表中选择提及的值。
在这里,我只想从下拉列表中选择这些@data-option-array-index=1,3,5,9,28,34
。
我想使用一种将仅针对这些选定值运行的数组或循环。 但是我做不到。
element=driver.findElement(By.xpath("//li[@class='search-field']"));
element.click();
element=driver.findElement(By.xpath("//li[@data-option-array-index='1']"));
element.click();
String text=driver.findElement(By.xpath("//li[@class='search-choice']")).getText();
System.out.println("Element text is: "+ text);
答案 0 :(得分:0)
使用findElements
List<WebElement> choises=driver.findElements(By.xpath("//li[@class='search-choice']"));
List<String> listValues= new Arraylist<String>();
for(WebElement choise : choises){
listValues.add(choise.getText());
}