Java tutorial
package com.sandstone_tech.lendfastselenium2.lfdapply.pageobjects.jointapplicantdetails; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.Select; import com.sandstone_tech.lendfastselenium2.common.BasePage; public class JointeeIdentityVerification extends BasePage { public JointeeIdentityVerification(WebDriver driver) { super(driver); } @Override public String getPageId() { return "/jointeeIdentityVerification"; } public void setIdentificationType(String identificationType) { if (identificationType.equalsIgnoreCase("Medicare")) { WebElement medicareButton = getElementByXpath("(//button[@name='MEDICARE'])[2]"); if (medicareButton != null) { click("(//button[@name='MEDICARE'])[2]"); } else { click("//button[@name='MEDICARE']"); } } else if (identificationType.equalsIgnoreCase("Drivers Licence")) { WebElement driversLicenceButton = getElementByXpath("(//button[@name='AUSDRIVELIC'])[2]"); if (driversLicenceButton != null) { click("(//button[@name='AUSDRIVELIC'])[2]"); } else { click("//button[@name='AUSDRIVELIC']"); } } else { WebElement passportButton = getElementByXpath("(//button[@name='PASSPORT'])[2]"); if (passportButton != null) { click("(//button[@name='PASSPORT'])[2]"); } else { click("//button[@name='PASSPORT']"); } } } public void setStateOfIssue(String stateOfIssue) { WebElement stateOfIssueField = getElementByXpath("(//select[@name='driverLicenceStateOfIssue'])[2]"); if (stateOfIssueField != null) { new Select(findByXpath("(//select[@name='driverLicenceStateOfIssue'])[2]")) .selectByVisibleText(stateOfIssue); } else { new Select(findByName("driverLicenceStateOfIssue")).selectByVisibleText(stateOfIssue); } } public void setLicenceNumber(String licenceNumber) { WebElement licenceNumberField = getElementByXpath("(//input[@name='driverLicenceNumber'])[2]"); if (licenceNumberField != null) { findByXpath("(//input[@name='driverLicenceNumber'])[2]").sendKeys(licenceNumber); } else { findByName("driverLicenceNumber").sendKeys(licenceNumber); } } public void setCardNumber(String cardNumber) { WebElement cardNumberField = getElementByXpath("(//input[@name='medicareCardNum'])[2]"); if (cardNumberField != null) { findByXpath("(//input[@name='medicareCardNum'])[2]").sendKeys(cardNumber); } else { findByName("medicareCardNum").sendKeys(cardNumber); } } public void setIndividualReferenceNumber(String referenceNumber) { WebElement indivRefField = getElementByXpath("(//input[@name='medicareCardNum'])[2]"); if (indivRefField != null) { new Select(findByXpath("(//select[@name='medicareReferenceNum'])[2]")) .selectByVisibleText(referenceNumber); } else { new Select(findByName("medicareReferenceNum")).selectByVisibleText(referenceNumber); } } public void setValidity(String months, String year) { WebElement validityField = getElementByXpath("(//input[@name='medicareExpiryDateMonth'])[2]"); if (validityField != null) { findByXpath("(//input[@name='medicareExpiryDateMonth'])[2]").sendKeys(months); findByXpath("(//input[@name='medicareExpiryDateYear'])[2]").sendKeys(year); } else { findByName("medicareExpiryDateMonth").sendKeys(months); findByName("medicareExpiryDateYear").sendKeys(year); } } public void setCardColor(String cardColor) { WebElement cardColorField = getElementByXpath("(//select[@name='medicareCardColour'])[2]"); if (cardColorField != null) { new Select(findByXpath("(//select[@name='medicareCardColour'])[2]")).selectByVisibleText(cardColor); } else { new Select(findByName("medicareCardColour")).selectByVisibleText(cardColor); } } public void setGender(String gender) { if (gender.equalsIgnoreCase("male")) { WebElement genderMaleButton = getElementByXpath("(//button[@name='gender'])[3]"); if (genderMaleButton != null) { click("(//button[@name='gender'])[3]"); } else { click("//button[contains(@ng-model,'model.passport.gender') and contains(@btn-radio,'MALE')]"); } } else { WebElement genderFmaleButton = getElementByXpath("(//button[@name='gender'])[4]"); if (genderFmaleButton != null) { click("(//button[@name='gender'])[4]"); } else { click("//button[contains(@ng-model,'model.passport.gender') and contains(@btn-radio,'FEMALE')]"); } } } public void setCountryCode(String countryCode) { WebElement countryCodeField = getElementByXpath("(//input[@name='passportCountryCode'])[2]"); if (countryCodeField != null) { findByXpath("(//input[@name='passportCountryCode'])[2]").sendKeys(countryCode); } else { findByName("passportCountryCode").sendKeys(countryCode); } findByCssSelector("a.ng-scope.ng-binding").click(); } public void setDocumentNumber(String documentNumber) { WebElement docNumField = getElementByXpath("(//input[@name='passportDocumentNum'])[2]"); if (docNumField != null) { findByXpath("(//input[@name='passportDocumentNum'])[2]").sendKeys(documentNumber); } else { findByName("passportDocumentNum").sendKeys(documentNumber); } } public void clickDone() { WebElement doneDriversButton = getElementByXpath( "(//div[@id='content']/div/div[2]/div[2]/div/div/form/div/button)[3]"); if (doneDriversButton != null) { click("(//div[@id='content']/div/div[2]/div[2]/div/div/form/div/button)[3]"); } else { click("(//div[@id='content']/div/div/div[2]/div[2]/div/div/form/div/button)[3]"); } } public void clickDoneOnMedicare() { WebElement doneMedicareButton = getElementByXpath( "(//div[@id='content']/div/div/div[2]/div/div/div/form/div/button)[7]"); if (doneMedicareButton != null) { click("(//div[@id='content']/div/div/div[2]/div/div/div/form/div/button)[7]"); } else { click("//div[@id='content']/div/div/div[2]/div/div/div/form/div/button"); } } public void clickDoneOnPassport() { WebElement donePassportButton = getElementByXpath( "(//div[@id='content']/div/div/div[2]/div[3]/div/div/form/div/button)[3]"); if (donePassportButton != null) { click("(//div[@id='content']/div/div/div[2]/div[3]/div/div/form/div/button)[3]"); } else { click("//div[@id='content']/div/div/div[2]/div[3]/div/div/form/div/button"); } } public void clickContinue() { WebElement elem = getElementByCssSelector( "form[name='jointeeIdentityVerificationForm'] > div.sst-dp-btn-wrapper > div.sst-dp-size-limit > div.sst-dp-padding > div.ng-isolate-scope > button[name='contBtn']"); JavascriptExecutor executor = (JavascriptExecutor) driver; if (elem != null) { executor.executeScript("arguments[0].click();", elem); } else { WebElement prodElem = driver.findElement(By.cssSelector( "form[name='jointeeIdentityVerificationForm'] > div.sst-dp-btn-wrapper > div.sst-dp-padding > div.ng-isolate-scope > button[name='contBtn']")); executor.executeScript("arguments[0].click();", prodElem); } } public void clickComeBackLater() { WebElement elem = driver.findElement(By.cssSelector( "form[name='jointeeIdentityVerificationForm'] > div.sst-dp-btn-wrapper > div.sst-dp-size-limit > div.sst-dp-padding > div.ng-isolate-scope > button[name='comeBackLaterBtn']")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", elem); } public void clickClear() { click("(//button[@type='button'])[9]"); } public void clickClearOnMedicare() { click("(//button[@type='button'])[8]"); } public void clickClearOnPassport() { WebElement clearPassportButton = getElementByXpath("(//button[@type='button'])[12]"); if (clearPassportButton != null) { click("(//button[@type='button'])[12]"); } else { click("(//button[@type='button'])[5]"); } } public void clickCancel() { WebElement elem = driver.findElement(By.cssSelector( "form[name='jointeeIdentityVerificationForm'] > div.sst-dp-btn-wrapper > div.sst-dp-size-limit > div.sst-dp-padding > div.ng-isolate-scope > button[name='cancelBtn']")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", elem); } public void clickCancelResponse(String yesOrNo) { if (yesOrNo.equalsIgnoreCase("Yes")) { } else { click("//button"); } } public void clickDoneOnEditing() { findByName("doneBtn").click(); } public void editIdentification() { click("div.sst-dp-link-title"); } public void setIdentificationType_PROD(String identificationType) { if (identificationType.equalsIgnoreCase("Medicare")) { WebElement medicareButton = getElementByXpath("(//button[@name=''])[4]"); if (medicareButton != null) { click("(//button[@name=''])[4]"); } else { click("//button[@name='']"); } } else if (identificationType.equalsIgnoreCase("Drivers Licence")) { WebElement licenseButton = getElementByXpath("(//button[@name=''])[5]"); if (licenseButton != null) { click("(//button[@name=''])[5]"); } else { click("(//button[@name=''])[2]"); } } else { WebElement passportButton = getElementByXpath("(//button[@name=''])[6]"); if (passportButton != null) { click("(//button[@name=''])[6]"); } else { click("(//button[@name=''])[3]"); } } } public void clickDoneOnDriversLicence_PROD() { WebElement licenseButton = getElementByXpath( "(//div[@id='content']/div/div/div[2]/div/div[2]/div/form/div/button)[3]"); if (licenseButton != null) { click("(//div[@id='content']/div/div/div[2]/div/div[2]/div/form/div/button)[3]"); } else { click("//div[@id='content']/div/div/div[2]/div/div[2]/div/form/div/button"); } } public void clickDoneOnMedicare_PROD() { WebElement medicareButton = getElementByXpath( "(//div[@id='content']/div/div/div[2]/div/div/div/form/div/button)[7]"); if (medicareButton != null) { click("(//div[@id='content']/div/div/div[2]/div/div/div/form/div/button)[7]"); } else { click("//div[@id='content']/div/div/div[2]/div/div/div/form/div/button"); } } public void clickDoneOnPassport_PROD() { WebElement passportButton = getElementByXpath( "(//div[@id='content']/div/div/div[2]/div/div[3]/div/form/div/button)[3]"); if (passportButton != null) { click("(//div[@id='content']/div/div/div[2]/div/div[3]/div/form/div/button)[3]"); } else { click("//div[@id='content']/div/div/div[2]/div/div[3]/div/form/div/button"); } } }