use of com.driver.locator.model.LocatorModel in project selenium_java by sergueik.
the class CsvFileWriter method writeToFile.
@Override
public boolean writeToFile(String fileName, List<LocatorModel> dData) {
try (CSVWriter writer = new CSVWriter(new FileWriter(ResourceHelper.getResourcePath("locator/") + fileName + ".csv", false), ',')) {
for (LocatorModel model : dData) {
String[] str = model.toString().split(":");
writer.writeNext(str, false);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of com.driver.locator.model.LocatorModel in project selenium_java by sergueik.
the class ElementLocator method getLocator.
public List<LocatorModel> getLocator(WebDriver aDriver) {
List<LocatorModel> locatorList = new ArrayList<LocatorModel>();
locatorList.addAll(getElementsByTag(TAG_LINK, aDriver));
locatorList.addAll(getElementsByTag(TAG_BUTTON, aDriver));
locatorList.addAll(getElementsByTag(TAG_DROP_DOWN, aDriver));
locatorList.addAll(getElementsByTag(TAG_INPUT, aDriver));
locatorList.addAll(getElementsByTag(TAG_TEXT_AREA, aDriver));
locatorList.addAll(getElementsByTag(TAG_SPAN, aDriver));
locatorList.removeIf(new NullRemove());
return locatorList;
}
use of com.driver.locator.model.LocatorModel in project selenium_java by sergueik.
the class ElementLocator method getXpath.
private LocatorModel getXpath(WebDriver aDriver, Element bElement) {
REC_COUNT = 1;
String locator = "";
Iterator<Attribute> attIterator = bElement.attributes().iterator();
List<String> locatorList = new ArrayList<>();
while (attIterator.hasNext()) {
Attribute attribute = (Attribute) attIterator.next();
if (IgnoreAttribute.ignoreAttribute.contains(attribute.getKey()) || attribute.getValue().isEmpty())
continue;
locator = "//" + bElement.nodeName() + "[@" + attribute.getKey() + "='" + attribute.getValue() + "']";
locatorList.add(locator);
if (isUnique(aDriver, By.xpath(locator)))
break;
locator = "";
}
return locator.length() == 0 ? getXpath(aDriver, bElement.parent(), locatorList.isEmpty() ? new ArrayList<String>(Arrays.asList("//" + bElement.nodeName())) : locatorList) : new LocatorModel("Xpath", locator);
}
use of com.driver.locator.model.LocatorModel in project selenium_java by sergueik.
the class ElementLocator method getElementsByTag.
private List<LocatorModel> getElementsByTag(String tagName, WebDriver aDriver) {
Elements eleList = dDocument.getElementsByTag(tagName);
List<LocatorModel> locator = new ArrayList<>();
for (int i = 0; i < eleList.size(); i++) {
locator.add(getUniqueLocator(aDriver, eleList.get(i)));
}
return locator;
}
use of com.driver.locator.model.LocatorModel in project selenium_java by sergueik.
the class ElementLocator method getXpath.
private LocatorModel getXpath(WebDriver aDriver, Element bElement, List<String> locatorList) {
boolean flag = true;
String locator = "";
Iterator<Attribute> attIterator = bElement.attributes().iterator();
List<String> locatorArrayList = new ArrayList<>();
if (REC_COUNT == 5 || bElement == null || locatorList.isEmpty())
return null;
REC_COUNT++;
while (attIterator.hasNext()) {
Attribute attribute = (Attribute) attIterator.next();
if (IgnoreAttribute.ignoreAttribute.contains(attribute.getKey()) || attribute.getValue().isEmpty())
continue;
for (String s : locatorList) {
locator = "//" + bElement.nodeName() + "[@" + attribute.getKey() + "='" + attribute.getValue() + "']" + s;
locatorArrayList.add(locator);
if (isUnique(aDriver, By.xpath(locator))) {
flag = false;
break;
}
locator = "";
}
if (!flag)
break;
}
if (locatorArrayList.isEmpty()) {
for (String s : locatorList) {
locator = "//" + bElement.nodeName() + s;
locatorArrayList.add(locator);
if (isUnique(aDriver, By.xpath(locator)))
break;
locator = "";
}
}
return locator.length() == 0 ? getXpath(aDriver, bElement.parent(), locatorArrayList) : new LocatorModel("Xpath", locator);
}
Aggregations