我们如何使用 Selenium WebDriver 将 Web 列表元素存储到数组中
例如:
weblist.get(j).findElement(By.className("accordion-toggle")).getText()
它包含我们如何将元素存储到数组中的元素列表。
最佳答案
你可以这样尝试
//to catch all web elements into list
List<WebElement> myList=driver.findElements(By.className("accordion-toggle"));
//myList contains all the web elements
//if you want to get all elements text into array list
List<String> all_elements_text=new ArrayList<>();
for(int i=0; i<myList.size(); i++){
//loading text of each element in to array all_elements_text
all_elements_text.add(myList.get(i).getText());
//to print directly
System.out.println(myList.get(i).getText());
}
谢谢
关于java - 我们如何使用 selenium webdriver 将 weblist 元素存储到数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34892868/