Example usage for org.openqa.selenium WebElement getText

List of usage examples for org.openqa.selenium WebElement getText

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getText.

Prototype

String getText();

Source Link

Document

Get the visible (i.e.

Usage

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void processDistrict(WebDriver driver, int districtIndex) {

    Select districtSelect = new Select(driver.findElement(By.name(Constants.DDL_DISTRICT)));
    districtSelect.selectByIndex(districtIndex);
    try {/*www. j a  va2 s .c o m*/
        TimeUnit.SECONDS.sleep(3);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    int blockSize = getRefreshedBlockSelect(driver, districtIndex).getOptions().size();

    if (logger.isDebugEnabled()) {
        logger.debug("processDistrict blockSize=" + blockSize); //$NON-NLS-1$
    }

    // Remove during production
    //blockSize =2;

    int startBlockIndex = new Integer(AmolikProperties.getProperty("odisha_ration.startBlockIndex")).intValue();
    ArrayList<OdishaRationCardBean> beanList = new ArrayList();

    for (int blockIndex = startBlockIndex; blockIndex < blockSize; blockIndex++) {

        Select blockSelect = getRefreshedBlockSelect(driver, districtIndex);
        List<WebElement> blocksList = blockSelect.getOptions();
        WebElement block = blocksList.get(blockIndex);

        if (logger.isDebugEnabled()) {

            logger.debug("processDistrict(WebDriver, int) - block=" + block.getText()); //$NON-NLS-1$
        }

        String blockValue = block.getAttribute(Constants.LOWERCASE_VALUE);

        if (logger.isDebugEnabled()) {

            logger.debug("processDistrict(WebDriver, int) - " + districtIndex + "|"
                    + block.getAttribute(Constants.LOWERCASE_VALUE) + "|" + block.getText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
        processBlock(driver, districtIndex, blockIndex, blockValue, block.getText(), beanList);
    }

    // Create new Directory if not exists
    String districtName = districtsNameList.get(districtIndex);
    String excelDestDirName = AmolikProperties.getProperty("odisha_ration.excelOutputDir");
    new File(excelDestDirName).mkdirs();

    String excelDestFileName = excelDestDirName + System.getProperty("file.separator") + districtName
            + excelFileExtension;

    if (logger.isInfoEnabled()) {

        logger.info("writing to excel " + districtIndex + "|" + districtName + "| toal recordCount="
                + (beanList.size()));
    }

    ExcelUtil.generateExcelFromBean(beanList, excelTemplateFileName, excelTemplateFileName, excelDestFileName,
            "rationCard");

}

From source file:com.artnaseef.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testSimple() throws Exception {
    this.driver.get(this.serverUrl + "index.html");

    String whoToSend = "foo";

    WebElement who = this.driver.findElement(By.id("who"));
    who.sendKeys(whoToSend);/*from w  w  w . j  a va  2 s  .c  o  m*/

    WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
    sendBtn.click();

    // wait 5 secs for ajax response
    new WebDriverWait(this.driver, 5)
            .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

    WebElement response = this.driver.findElement(By.id("response"));
    String text = response.getText();

    Assert.assertEquals("Hello " + whoToSend, text);

}

From source file:com.atlassian.webdriver.greenhopper.page.admin.GreenHopperLicenseDetailsPage.java

@Init
private void readLicense() {
    if (Check.elementExists(By.className("errMsg"), updateLicenseForm)) {
        errorMessage = updateLicenseForm.findElement(By.className("errMsg")).getText();
    }//from  ww w .j a v  a 2s .c o  m

    List<WebElement> rows = licenseTable.findElements(By.tagName("tr"));

    organisation = rows.get(0).findElement(ByJquery.$("td ~ td")).getText();

    if (StringUtils.isNotEmpty(organisation)) {
        licenseIsLoaded = true;

        purchaseDate = formatDate(rows.get(1).findElement(ByJquery.$("td ~ td strong")).getText());

        WebElement licenseTypeColumn = rows.get(2).findElement(ByJquery.$("td ~ td"));

        licenseType = licenseTypeColumn.findElement(By.tagName("strong")).getText();
        expiryDate = formatDate(extractExpiryDate(licenseTypeColumn.getText()));

        serverId = rows.get(3).findElement(ByJquery.$("td ~ td strong")).getText();

        supportEntitlmentNumber = rows.get(4).findElement(ByJquery.$("td ~ td strong")).getText();

    }

}

From source file:com.atomicleopard.webelemental.ElementTest.java

License:Open Source License

public static WebElement webElement(String element, String text, final Map<String, String> attributes) {
    WebElement webElement = mock(WebElement.class);
    when(webElement.getTagName()).thenReturn(element);
    when(webElement.getText()).thenReturn(text);
    when(webElement.getAttribute(anyString())).thenAnswer(new Answer<String>() {
        public String answer(InvocationOnMock invocation) throws Throwable {
            String key = (String) invocation.getArguments()[0];
            return attributes.get(key);
        }//from w ww.j a v  a 2s.c om
    });

    return webElement;
}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public boolean isDropDownSelectedText(Select selectElement, String text) {
    List<WebElement> selectedOptions = selectElement.getAllSelectedOptions();
    for (WebElement option : selectedOptions) {
        if (option.getText().equals(text))
            return true;
    }/*from   w ww  .  j a va 2  s.c  om*/
    return false;
}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public ArrayList<String> getDropDownOptionLabels(Select selectControl) {
    ArrayList<String> texts = new ArrayList<String>();
    for (WebElement option : selectControl.getOptions()) {
        texts.add(option.getText());
    }/*from   w w w. j a  va  2  s. c  o  m*/
    return texts;
}

From source file:com.autocognite.selenium.lib.base.DefaultSeleniumMediator.java

License:Apache License

@Override
public UiElement getInstanceByText(String text) throws Exception {
    identifyAllIfNull();//from w  w w.j  av  a 2s . c  om
    for (WebElement element : this.getToolElements()) {
        if (element.getText().equals(text)) {
            return this.getUiElementWrapperForToolElement(element);
        }
    }
    throw new Exception("None of the element instances has the specified text.");
}

From source file:com.autocognite.selenium.lib.base.DefaultSeleniumMediator.java

License:Apache License

@Override
public UiElement getInstanceByTextContent(String text) throws Exception {
    identifyAllIfNull();//from ww w  .j a  v  a2  s  .c o  m
    for (WebElement element : this.getToolElements()) {
        if (element.getText().contains(text)) {
            return this.getUiElementWrapperForToolElement(element);
        }
    }
    throw new Exception("None of the element instances has the specified text content.");
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public String getText(WebElement wdElement) {
    return wdElement.getText();
}

From source file:com.bc.opec.webtests.WebTestBase.java

License:Open Source License

public void closePopups() {
    Assert.assertTrue(driver.getTitle().startsWith("OPEC"));
    for (WebElement e : driver.findElements(By.tagName("Button"))) {
        if (e.getAttribute("title").equals("Close")) {
            e.click();/*from  w ww. j  a  v a2s  . c  om*/
            break;
        }
    }
    for (WebElement e : driver.findElements(By.tagName("Button"))) {
        if (e.getText().equals("No")) {
            e.click();
            break;
        }
    }
    driver.findElement(
            By.xpath("//*/div[@aria-describedby='gisportal-layerSelection']/div/div/button[@title='close']"))
            .click();
}