Java tutorial
package easycare.cuke.pageObjects.patient; import easycare.cuke.Alias; import easycare.cuke.pageObjects.PageUrls; import easycare.cuke.pageObjects.PaginablePage; import org.apache.commons.collections.map.CaseInsensitiveMap; import org.apache.commons.lang.StringUtils; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; @Component @Alias(PageUrls.PATIENT_PHYSICIAN_SEARCH_RESULT_URL) public class PatientPhysicianSearchResultPage extends PaginablePage { public List<Map<String, String>> extractPhysicians() { List<Map<String, String>> physicians = new ArrayList<>(); List<WebElement> physicianOrgTableList = findElementsByCssSelector("table.physicianOrg"); for (WebElement physicianOrgTable : physicianOrgTableList) { String organisation = physicianOrgTable.findElement(By.cssSelector("th.orgName")).getText(); List<WebElement> physicianRowList = physicianOrgTable.findElements(By.cssSelector("tbody > tr")); for (WebElement physicianRow : physicianRowList) { @SuppressWarnings("unchecked") Map<String, String> physician = new CaseInsensitiveMap(); physician.put("physician name", getElementTextByCss(physicianRow, "td.physicianName")); // cannot use getElementTextByCss here as license number could // be blank String licenseNumber = physicianRow.findElement(By.cssSelector("td.license")).getText(); if (StringUtils.isBlank(licenseNumber)) { licenseNumber = "<BLANK>"; } physician.put("license number", licenseNumber); physician.put("address", getElementTextByCss(physicianRow, "td.address")); physician.put("organisation", organisation); physicians.add(physician); } } return physicians; } @Override protected String getUrl() { return null; } public void selectPhysicianToAdd(String physicianName) { List<WebElement> physicianOrgDataTableList = findElementsByCssSelector("table.physicianOrg"); for (WebElement physicianOrgDataTable : physicianOrgDataTableList) { WebElement orgNameInList = physicianOrgDataTable.findElement(By.cssSelector("th.orgName a")); String organisation = StringUtils.trim(orgNameInList.getText()); if (organisation.equalsIgnoreCase(physicianName)) { orgNameInList.click(); return; } List<WebElement> physicianRowList = physicianOrgDataTable.findElements(By.cssSelector("tbody > tr")); for (WebElement physicianRow : physicianRowList) { WebElement physicianNameAsElement = physicianRow.findElement(By.cssSelector("td.physicianName a")); String physicianNameAsString = physicianNameAsElement.getText(); if (physicianNameAsString.toUpperCase().contains(physicianName.toUpperCase())) { physicianNameAsElement.click(); return; } } } throw new IllegalStateException("No physician on page matching " + physicianName); } }