Using below code I am able to store complete table but not sure how to fetch data with condition like find one data if available store from there.
for example(from given table) Check for NameDetails if found store data from row 6 to row 8 from table Any help would be appreciated.
public Map<String, String> fetchTableData(String tableLocator) throws SeleniumException {
Map<String, String> actualtable = new HashMap<>();
try {
findElements(By.xpath(commonLocator.getElementsByTagName(tableLocator).item(0).getTextContent()),
"Capturing lables");
int count = 0;
for (int i = 1; i <= _WebElements.size() - 1; i++) {
if (_WebElements.get(i).getText().equals(""))
continue;
List<WebElement> td = (List<WebElement>) _WebElements.get(i).findElements(
By.cssSelector(commonLocator.getElementsByTagName("tableData").item(0).getTextContent()));
if (td.get(0).getText().equals("All")) {
switch (count) {
case 0:
actualtable.put("first_" + td.get(0).getText().replaceAll("\\s+", ""),
td.get(1).getText());
break;
case 1:
actualtable.put("second_" + td.get(0).getText().replaceAll("\\s+", ""),
td.get(1).getText());
break;
}
count++;
} else {
if(td.get(0).getText().equals("")||td.get(1).getText().equals("Management Domain"))
continue;
actualtable.put(td.get(0).getText().replaceAll("\\s+", ""), td.get(1).getText());
}
}
Log.info(actualtable);
}
catch (Exception e) {
Log.error("Can not store data, locators not found");
e.printStackTrace();
}
return actualtable;
}
Aucun commentaire:
Enregistrer un commentaire