List of usage examples for org.openqa.selenium WebElement getText
String getText();
From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java
License:Open Source License
/** * Gets the element by sub element text. * @param driver the driver// w w w . j ava 2 s. c om * @param subElement the sub element * @param locator the locator * @param textValue the text value * @param timeout the timeout * @return the element by sub element text */ public static WebElement getElementBySubElementText(final WebDriver driver, final WebElement subElement, final By locator, final String textValue, final CustomTimeout timeout) { WebElement elementAttrValue = null; final List<WebElement> elementList = getElementsBySubElement(driver, subElement, locator, timeout); for (final WebElement webElement : elementList) { final String valueAttribute = webElement.getText(); if (valueAttribute.trim().equalsIgnoreCase(textValue)) { elementAttrValue = webElement; } } return elementAttrValue; }
From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java
License:Open Source License
/** * Gets the elements by sub element text. * @param driver the driver// w w w.j av a 2 s .com * @param subElement the sub element * @param locator the locator * @param textValue the text value * @param timeout the timeout * @return the elements by sub element text */ public static List<WebElement> getElementsBySubElementText(final WebDriver driver, final WebElement subElement, final By locator, final String textValue, final CustomTimeout timeout) { final List<WebElement> eleList = new ArrayList<>(); final List<WebElement> elementList = getElementsBySubElement(driver, subElement, locator, timeout); for (final WebElement webElement : elementList) { final String valueAttribute = webElement.getText().trim(); if (valueAttribute.trim().equalsIgnoreCase(textValue)) { eleList.add(webElement); } } return eleList; }
From source file:com.ecofactor.qa.automation.util.mail.Gmail.java
License:Open Source License
/** * Gets the changed password.//from w w w . j ava 2s . c o m * @param url the url * @param emailUserName the email user name * @param emailPassword the email password * @param subject the subject * @param boldIndex the bold index * @param pwdIndex the pwd index * @return the changed password */ public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject, int boldIndex, int pwdIndex) { WebDriver driver = DriverConfig.getDriver(); if (DriverConfig.getDriver() == null) { driverConfig.loadDriver(); driver = DriverConfig.getDriver(); } String tempPassword = null; largeWait(); DriverConfig.setLogString("Load Email portal URL at change password", true); driver.navigate().to(url + "" + emailUserName); largeWait(); boolean session = isDisplayedById(driver, "Passwd", MEDIUM_TIMEOUT); if (session) { DriverConfig.setLogString( "Enter username and password for Email(" + emailUserName + "/" + emailPassword + ")", true); driver.findElement(By.id("Email")).sendKeys(emailUserName); driver.findElement(By.id("Passwd")).sendKeys(emailPassword); mediumWait(); WebElement signInButtonElement = driver.findElement(By.id("signIn")); DriverConfig.setLogString("click Sign In button", true); signInButtonElement.click(); largeWait(); boolean button = isDisplayedById(driver, "no-button", MEDIUM_TIMEOUT); if (button) { WebElement buttonElement = driver.findElement(By.id("no-button")); buttonElement.click(); mediumWait(); } } isDisplayedByCSS(driver, ".aio.UKr6le", MEDIUM_TIMEOUT); DriverConfig.setLogString("Click Inbox.", true); WebElement inboxElement = DriverConfig.getDriver().findElement(By.partialLinkText("Inbox")); inboxElement.click(); largeWait(); DriverConfig.setLogString("Click Subject of Email.", true); WebElement webElement = driver.findElement(By.cssSelector(".ae4.UI.UJ")); List<WebElement> tagElement = webElement.findElements(By.tagName(TAG_BOLD)); WebElement firstElement = tagElement.get(0); if (firstElement != null && firstElement.isDisplayed() && firstElement.getText().equalsIgnoreCase(subject)) { firstElement.click(); largeWait(); } DriverConfig.setLogString("Get temporary Password/activation link from Email.", true); if (boldIndex == 1) { WebElement divBodyElement = driver.findElement(By.xpath("//*[contains(@class,'adO')]")); if (pwdIndex == 1) { WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_STRONG)).get(0); tempPassword = pwdElement.getText(); DriverConfig.setLogString("Temporary password got from email " + tempPassword, true); } else { WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_ANCHOR)).get(0); tempPassword = pwdElement.getText(); DriverConfig.setLogString("Activation link got from email " + tempPassword, true); } } else if (boldIndex == 0) { DriverConfig.setLogString("Header Tag", true); WebElement divBodyElement = driver.findElement(By.className("gs")); List<WebElement> headerElement = divBodyElement.findElements(By.tagName("strong")); for (WebElement webelement : headerElement) { if (webelement.isDisplayed()) { tempPassword = webelement.getText(); DriverConfig.setLogString("Temporary password got from email " + tempPassword, true); } } } mediumWait(); deleteFirstMail(driver); DriverConfig.setLogString("Click user for Signout option", true); boolean value = isDisplayedById(DriverConfig.getDriver(), "gbgs4dn", MEDIUM_TIMEOUT); DriverConfig.setLogString("User name displayed for sign out : " + value, true); if (value) { driver.findElement(By.id("gbgs4dn")).click(); } else { WebElement signOutElement = DriverConfig.getDriver().findElement(By.partialLinkText(emailUserName)); signOutElement.click(); } smallWait(); DriverConfig.setLogString("Click Signout", true); driver.findElement(By.id("gb_71")).click(); mediumWait(); mediumWait(); return tempPassword; }
From source file:com.ecofactor.qa.automation.util.mail.Gmail.java
License:Open Source License
/** * Delete first mail./*from w w w.j a v a 2 s.c o m*/ * @param driver the driver */ public void deleteFirstMail(WebDriver driver) { DriverConfig.setLogString("Delete First Mail", true); DriverConfig.setLogString("Click Inbox", true); WebElement inboxElement = DriverConfig.getDriver().findElement(By.partialLinkText("Inbox")); inboxElement.click(); mediumWait(); DriverConfig.setLogString("Click Subject of Email.", true); boolean subjectDisplayed = isDisplayedByCSS(driver, ".ae4.UI.UJ", MEDIUM_TIMEOUT); if (subjectDisplayed) { WebElement webElement1 = driver.findElement(By.cssSelector(".ae4.UI.UJ")); if (!webElement1.getText().contains("No new mail")) { WebElement firstElement2 = null; if (webElement1 != null && webElement1.findElements(By.tagName(TAG_BOLD)) != null && webElement1.findElements(By.tagName(TAG_BOLD)).size() > 0) { firstElement2 = webElement1.findElements(By.tagName(TAG_BOLD)).get(0); } else { firstElement2 = webElement1.findElements(By.cssSelector("td.yX.xY")).get(0); } if (firstElement2 != null && firstElement2.isDisplayed()) { firstElement2.click(); mediumWait(); DriverConfig.setLogString("Delete the Email", true); if (driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) != null && driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")).size() == 2) { DriverConfig.setLogString("Click delete old mails", true); WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) .get(1); webElement2.click(); } else { DriverConfig.setLogString("Click delete old mails", true); smallWait(); WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) .get(1); webElement2.click(); } smallWait(); } } } }
From source file:com.ecofactor.qa.automation.util.mail.GmailForNewUser.java
License:Open Source License
/** * Gets the changed password.//from w ww. j a va2 s .co m * @param url the url * @param emailUserName the email user name * @param emailPassword the email password * @param subject the subject * @param boldIndex the bold index * @param pwdIndex the pwd index * @return the changed password */ public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject, int boldIndex, int pwdIndex) { if (gmailDriver == null) { gmailDriver = new ChromeDriver(); } String tempPassword = null; largeWait(); DriverConfig.setLogString("Load Email portal URL at change password", true); DriverConfig.setLogString("URL : " + url + "" + emailUserName, true); gmailDriver.navigate().to(url + "" + emailUserName); largeWait(); boolean session = isDisplayedById(gmailDriver, "Passwd", MEDIUM_TIMEOUT); if (session) { DriverConfig.setLogString( "Enter username and password for Email(" + emailUserName + "/" + emailPassword + ")", true); if (isDisplayedById(gmailDriver, "reauthEmail", SHORT_TIMEOUT) && gmailDriver.findElement(By.id("reauthEmail")).getText().equalsIgnoreCase(emailUserName)) { clearAndInput(gmailDriver, By.id("Passwd"), emailPassword); } else { clearAndInput(gmailDriver, By.id("Email"), emailUserName); clearAndInput(gmailDriver, By.id("Passwd"), emailPassword); } mediumWait(); WebElement signInButtonElement = gmailDriver.findElement(By.id("signIn")); DriverConfig.setLogString("click Sign In button", true); signInButtonElement.click(); largeWait(); boolean button = isDisplayedById(gmailDriver, "no-button", MEDIUM_TIMEOUT); if (button) { WebElement buttonElement = gmailDriver.findElement(By.id("no-button")); buttonElement.click(); mediumWait(); } } isDisplayedByCSS(gmailDriver, ".aio.UKr6le", MEDIUM_TIMEOUT); DriverConfig.setLogString("Click Inbox.", true); WebElement inboxElement = gmailDriver.findElement(By.partialLinkText("Inbox")); inboxElement.click(); largeWait(); DriverConfig.setLogString("Click Subject of Email.", true); DriverConfig.setLogString("Subject of Email : " + subject, true); WebElement webElement = gmailDriver.findElement(By.cssSelector(".ae4.UI.UJ")); List<WebElement> tagElement = webElement.findElements(By.tagName(TAG_BOLD)); WebElement firstElement = tagElement.get(0); if (firstElement != null && firstElement.isDisplayed() && firstElement.getText().equalsIgnoreCase(subject)) { firstElement.click(); largeWait(); } DriverConfig.setLogString("Get temporary Password/activation link from Email.", true); if (boldIndex == 1) { WebElement divBodyElement = gmailDriver.findElement(By.xpath("//*[contains(@class,'adO')]")); if (pwdIndex == 1) { WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_STRONG)).get(0); tempPassword = pwdElement.getText(); DriverConfig.setLogString("Temporary password got from email " + tempPassword, true); } else { WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_ANCHOR)).get(0); tempPassword = pwdElement.getText(); DriverConfig.setLogString("Activation link got from email " + tempPassword, true); } } else if (boldIndex == 0) { DriverConfig.setLogString("Header Tag", true); WebElement divBodyElement = gmailDriver.findElement(By.className("gs")); List<WebElement> headerElement = divBodyElement.findElements(By.tagName("strong")); for (WebElement webelement : headerElement) { if (webelement.isDisplayed()) { tempPassword = webelement.getText(); DriverConfig.setLogString("Temporary password got from email " + tempPassword, true); } } } mediumWait(); deleteFirstMail(gmailDriver); DriverConfig.setLogString("Click user for Signout option", true); boolean value = isDisplayedById(gmailDriver, "gbgs4dn", MEDIUM_TIMEOUT); DriverConfig.setLogString("User name displayed for sign out : " + value, true); if (value) { gmailDriver.findElement(By.id("gbgs4dn")).click(); } else { WebElement signOutElement = gmailDriver.findElement(By.partialLinkText(emailUserName)); signOutElement.click(); } smallWait(); DriverConfig.setLogString("Click Signout", true); gmailDriver.findElement(By.id("gb_71")).click(); mediumWait(); mediumWait(); gmailDriver.close(); gmailDriver.quit(); gmailDriver = null; return tempPassword; }
From source file:com.ecofactor.qa.automation.util.mail.GmailForNewUser.java
License:Open Source License
/** * Delete first mail./*from w ww . jav a 2s. c o m*/ * @param driver the driver */ public void deleteFirstMail(WebDriver driver) { DriverConfig.setLogString("Delete First Mail", true); DriverConfig.setLogString("Click Inbox", true); WebElement inboxElement = driver.findElement(By.partialLinkText("Inbox")); inboxElement.click(); mediumWait(); DriverConfig.setLogString("Click Subject of Email.", true); // boolean subjectDisplayed=isDisplayedByTagName(driver, TAG_BOLD, MEDIUM_TIMEOUT); boolean subjectDisplayed = isDisplayedByCSS(driver, ".ae4.UI.UJ", MEDIUM_TIMEOUT); if (subjectDisplayed) { WebElement webElement1 = driver.findElement(By.cssSelector(".ae4.UI.UJ")); // WebElement webElement1 = driver.findElement(By.xpath(".//*[span]")); if (!webElement1.getText().contains("No new mail")) { WebElement firstElement2 = null; if (webElement1 != null && webElement1.findElements(By.tagName(TAG_BOLD)) != null && webElement1.findElements(By.tagName(TAG_BOLD)).size() > 0) { firstElement2 = webElement1.findElements(By.tagName(TAG_BOLD)).get(0); } else { firstElement2 = webElement1.findElements(By.cssSelector("td.yX.xY")).get(0); } if (firstElement2 != null && firstElement2.isDisplayed()) { firstElement2.click(); mediumWait(); DriverConfig.setLogString("Delete the Email", true); if (driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) != null && driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")).size() == 2) { DriverConfig.setLogString("Click delete old mails", true); WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) .get(1); webElement2.click(); } else { DriverConfig.setLogString("Click delete old mails", true); smallWait(); WebElement webElement2 = driver.findElements(By.cssSelector("div.ar9.T-I-J3.J-J5-Ji")) .get(1); webElement2.click(); } smallWait(); } } } }
From source file:com.ecofactor.qa.automation.util.mail.OutlookMail.java
License:Open Source License
/** * Gets the changed password.//from w w w. jav a 2 s . c om * @param driver the driver * @param url the url * @param emailUserName the email user name * @param emailPassword the email password * @param subject the subject * @param boldIndex the bold index * @return the changed password */ public String getChangedPassword(String url, String emailUserName, String emailPassword, String subject, int boldIndex) { WebDriver driver = driverConfig.getDriver(); DriverConfig.setLogString("Load Email portal URL.", true); driver.navigate().to(url); largeWait(); DriverConfig.setLogString("Enter Username/Password for Email.", true); driver.findElement(By.id("cred_userid_inputtext")).sendKeys(emailUserName); driver.findElement(By.id("cred_password_inputtext")).sendKeys(emailPassword); smallWait(); DriverConfig.setLogString("Click Login.", true); WebElement signInButtonElement = driver.findElement(By.cssSelector("#cred_sign_in_button")); DriverConfig.setLogString("send keys to login", true); signInButtonElement.sendKeys(Keys.RETURN); largeWait(); DriverConfig.setLogString("click btn", true); signInButtonElement.click(); largeWait(); DriverConfig.setLogString("Click Inbox.", true); WebElement outLookMenu = retrieveElementByTagText(driver, TAG_SPAN, "Outlook"); if (outLookMenu != null && outLookMenu.isDisplayed()) { outLookMenu.click(); mediumWait(); } DriverConfig.setLogString("Click Subject of Email.", true); List<WebElement> subElements = retrieveElementsByTagText(driver, TAG_SPAN, subject); if (subElements.size() > 0) { subElements.get(0).click(); mediumWait(); } largeWait(); DriverConfig.setLogString("Get temporary Password from Email.", true); WebElement divBodyElement = driver.findElement(By.id("Item.MessagePartBody")); mediumWait(); WebElement pwdElement = divBodyElement.findElements(By.tagName(TAG_BOLD)).get(boldIndex); String tempPassword = pwdElement.getText(); DriverConfig.setLogString("Temporary password got from email " + tempPassword, true); DriverConfig.setLogString("Click user for Signout option", true); WebElement menuElement = retrieveElementByAttributeValue(driver, TAG_BUTTON, ATTR_CLASS, "button _hl_2 _hl_e"); menuElement.click(); smallWait(); DriverConfig.setLogString("Click Signout", true); WebElement signOut = retrieveElementByTagText(driver, TAG_SPAN, "sign out", MEDIUM_TIMEOUT); signOut.click(); smallWait(); return tempPassword; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Utility to check weather the particular field is displayed by field name and the text value. * @param driver the driver/*from w w w .j av a 2 s .co m*/ * @param fieldname the fieldname * @param textValue the text value * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByText(final WebDriver driver, final String fieldname, final String textValue, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { WebElement element = d.findElement(By.id(fieldname)); return element.getText().contains(textValue); } }); return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Utility to check weather the particular field is displayed by css class name. * @param driver the driver/*from ww w . j a v a 2s. c o m*/ * @param fieldname the fieldname * @param textValue the text value * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByClassNameText(final WebDriver driver, final String fieldname, final String textValue, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { WebElement element = d.findElement(By.className(fieldname)); return element.getText().contains(textValue); } }); return isLoaded; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Check particular web Element text contains the expected text. * @param driver the driver//from w w w.j ava 2s .c om * @param element the element * @param textValue the text value * @param timeOut the time out * @return boolean */ public static boolean isDisplayedByElementText(final WebDriver driver, final WebElement element, final String textValue, final int timeOut) { boolean isLoaded = false; isLoaded = (new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return element.getText().contains(textValue); } }); return isLoaded; }