List of usage examples for org.openqa.selenium WebElement getText
String getText();
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Gets the element by text contains.//from w w w . j a va2 s.c om * * @param driver the driver * @param locator the locator * @param innerText the inner text * @param timeout the timeout * @return the element by text contains */ public static WebElement getElementByTextContains(final WebDriver driver, final By locator, final String innerText, final Timeout timeout) { for (final WebElement webElement : getElements(driver, locator, timeout)) { if (webElement.isDisplayed() && webElement.isEnabled() && webElement.getText().trim().contains(innerText)) { return webElement; } } return null; }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Gets the element by sub element text. * /*from ww w.j a v a 2 s.com*/ * @param driver the driver * @param subElement the sub element * @param locator the locator * @param innerText the inner text * @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 innerText, final Timeout timeout) { for (final WebElement webElement : getElementsBySubElement(driver, subElement, locator, timeout)) { final String valueAttribute = webElement.getText(); if (valueAttribute.trim().equalsIgnoreCase(innerText)) { return webElement; } } return null; }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Gets the element by sub element text contains. * /* w w w . j av a 2s.c o m*/ * @param driver the driver * @param subElement the sub element * @param locator the locator * @param innerText the inner text * @param timeout the timeout * @return the element by sub element text contains */ public static WebElement getElementBySubElementTextContains(final WebDriver driver, final WebElement subElement, final By locator, final String innerText, final Timeout timeout) { for (final WebElement webElement : getElementsBySubElement(driver, subElement, locator, timeout)) { final String valueAttribute = webElement.getText(); if (valueAttribute.trim().contains(innerText)) { return webElement; } } return null; }
From source file:com.coderoad.automation.common.util.PageUtil.java
License:Open Source License
/** * Method to set date in a date picker//from w ww. ja va 2 s. c o m * @author Ruth Chirinos * @param driver the WebDriver * @param xpathDatePicker the xpath of the datePicker * @param vehicleSelectionPage * year - the year minus 1900. * month - the month between 0-11. * date - the day of the month between 1-31. * @throws InterruptedException * @throws ParseException */ public static boolean setDateInDatePicker(WebDriver driver, String xpathDatePicker, Date dateRequested) throws InterruptedException, ParseException { Calendar dateRequestedCalendar = DateUtil.getCalendarForDate(dateRequested); LogUtil.log("Date for changing is > " + DateUtil.format(dateRequestedCalendar, DateUtil.DATE_MONTH_ABBREVIATION), LogLevel.LOW); boolean processOk = false; String dateSelectedString = ""; Date dateSelected = null; SimpleDateFormat simpleFormat = new SimpleDateFormat(DateUtil.DATE_MONTH_YEAR_FMT); WebElement datePicker = driver.findElement(By.xpath(xpathDatePicker)); datePicker.click(); WebElement monthYearElement = driver .findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); WebElement daySelected = driver.findElement(By.xpath("//*[contains(@class, 'x-datepicker-selected')]/a")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); WebElement pickerPrevEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-prev')]")); WebElement pickerNextEl = driver.findElement( By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-next')]")); //Choosing the year while (dateRequested.getYear() < dateSelected.getYear()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getYear() > dateSelected.getYear()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the months while (dateRequested.getMonth() < dateSelected.getMonth()) { pickerPrevEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } while (dateRequested.getMonth() > dateSelected.getMonth()) { pickerNextEl.click(); monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]")); dateSelectedString = daySelected.getAttribute("innerHTML") + " " + monthYearElement.getAttribute("innerHTML"); dateSelected = simpleFormat.parse(dateSelectedString); } //Choosing the day WebElement dateWidget = driver.findElement(By.className("x-datepicker-inner")); List<WebElement> columns = dateWidget.findElements(By.tagName("td")); int aux = 0; for (WebElement cell : columns) { if (cell.getText().equals(dateRequested.getDate() + "")) { processOk = cell.getAttribute("class").contains("x-datepicker-active"); if (processOk) { cell.findElement(By.tagName("a")).click(); ; LogUtil.log("The date was selected.", LogLevel.LOW); aux = 1; break; } } } if (aux == 0) { LogUtil.log("The date selected is not enabled.", LogLevel.LOW); } return processOk; }
From source file:com.coderoad.automation.rocketTruedx.RocketTruedxNaBasePage.java
License:Open Source License
/** * this method selects the options from the combobox. * /*ww w . j a v a 2 s.co m*/ * @param dropDown the drop down * @param option the option */ protected void selectOptionIn(WebElement dropDown, String option) { String triggerId = dropDown.getAttribute("id"); WebElement arrow = dropDown.findElement(By.id(triggerId)); if (arrow.isDisplayed()) { arrow.click(); } WaitUtil.waitUntil(5); List<WebElement> options = getDriver().findElements(By.xpath("//li[@role='option']")); for (WebElement opt : options) { if (opt.getText().equalsIgnoreCase(option)) { click(opt); WaitUtil.waitUntil(2); break; } } }
From source file:com.cognifide.aet.sanity.functional.cucumber.CommonSteps.java
License:Apache License
@And("^Statistics text contains \"([^\"]*)\"$") public void statisticsTextContains(String expectedText) throws Throwable { WebElement statistics = reportHomePage.getAside().getStatistics(); String actual = statistics.getText(); assertTrue("statistics text should contain '" + expectedText + "'", actual.contains(expectedText)); }
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.AemRadioOption.java
License:Apache License
/** * Support for both widgets (xtype=radiogroup) and (xtype=selection, type=radio). Depends on which widget * is used the first or second label is filled. * * @return label of element or "" in case of no label *//*from w w w . ja v a 2 s . c om*/ public String getLabel() { for (WebElement element : labels) { String label = getUnescapedText(element.getText()); if (StringUtils.isNotBlank(label)) { return label; } } return ""; }
From source file:com.cognifide.qa.bb.aem.dialog.classic.field.AemRichText.java
License:Apache License
/** * Clears the content of richtext's text area. * * @return This instance.//w w w . j av a2s . c o m */ public AemRichText clear() { switchToTextArea(); try { bobcatWait.withTimeout(Timeouts.BIG).until(driver -> { actions.sendKeys(Keys.chord(Keys.CONTROL, "a")).sendKeys(Keys.BACK_SPACE).sendKeys(Keys.BACK_SPACE) .perform(); WebElement activeElement = webDriver.switchTo().activeElement(); String text = activeElement.getText(); return text.isEmpty(); }, 2); return this; } finally { frameSwitcher.switchBack(); } }
From source file:com.cognifide.qa.bb.aem.ui.AemContentFinderTab.java
License:Apache License
/** * See {@link AemContentFinder#getResults} * * @return elements showed in the tab/*w ww . j a v a 2 s .c o m*/ */ public List<String> getResults() { List<WebElement> list = resultsPanel .findElements(By.xpath(".//div[contains(@class,'cq-cft-search-title')]")); List<String> results = new ArrayList<>(list.size()); for (WebElement webElement : list) { results.add(webElement.getText()); } return results; }
From source file:com.cognifide.qa.bb.aem.ui.AemDialog.java
License:Apache License
/** * @return Edit Window's title.//from w w w.j a va 2 s. co m */ public String getTitle() { WebElement windowTitle = webDriver.findElement(By.xpath(DIALOG_XPATH + CONFIG_WINDOW_TITLE_XPATH)); return windowTitle.getText(); }