Selenium Web驱动程序与Java(Angular应用程序)



我已经编写了以下代码,用于从下拉列表中选择上述值
在这里,我只想从下拉列表中选择这些@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);

使用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());
}

相关内容

最新更新