简体   繁体   中英

Selenium Webdriver with Java (Angular application)

I have written below code for selecting mentioned values from the drop-down list.
Here I want to select only these @data-option-array-index=1,3,5,9,28,34 from the drop-down list.
I want to use kind of array or loop in which it will run for these selected values only. But I am unable to do it .

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM