I've got multiple div on a webpage that have the same class attribute. I'm looking for a way to check all the div of my page for a specific class name, and then get, for each of this div, their Xpath.
Actually, i can check how many div i have on the page with a class name :
List<WebElements> test = driver.findElements(By.className("fitter"));
int countDiv = test.size();
Do you have an idea, now, to get all my elements Xpath one by one ? Or have you a different solution ?
My project is a Selenium project and i'm testing a web page. My test are written in Java and i'm using WebDriver.
thanks for help
Simply iterate through the list of webelements?
List<WebElement> elements = driver.findElements(By.className("fitter"));
for (int i = 0; i < elements.size(); i++) {
WebElement element = elements.get(i);
// ... do whatever you need here
}
The xpath of each element in the loop would be
//div[contains(@class, 'fitter')][i]
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.