Example usage for org.openqa.selenium By tagName

List of usage examples for org.openqa.selenium By tagName

Introduction

In this page you can find the example usage for org.openqa.selenium By tagName.

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:com.mkl.websuites.command.OperationOnWebElement.java

License:Apache License

@Override
protected void runCommandWithParameters() {

    by = null;//  w  ww  .jav  a  2 s.c  o  m

    if (parameterMap.keySet().contains("id")) {
        by = By.id(parameterMap.get("id"));
    }

    if (parameterMap.keySet().contains("css")) {
        by = By.cssSelector(parameterMap.get("css"));
    }

    if (parameterMap.keySet().contains("xpath")) {
        by = By.xpath(parameterMap.get("xpath"));
    }

    if (parameterMap.keySet().contains("className")) {
        by = By.className(parameterMap.get("className"));
    }

    if (parameterMap.keySet().contains("linkText")) {
        by = By.linkText(parameterMap.get("linkText"));
    }

    if (parameterMap.keySet().contains("partialLinkText")) {
        by = By.partialLinkText(parameterMap.get("partialLinkText"));
    }

    if (parameterMap.keySet().contains("name")) {
        by = By.name(parameterMap.get("name"));
    }

    if (parameterMap.keySet().contains("tagName")) {
        by = By.tagName(parameterMap.get("tagName"));
    }

    try {

        WebElement elem = browser.findElement(by);

        foundElement = elem;

        doOperationOnElement(elem);

    } catch (NoSuchElementException e) {

        fail("No element found for selecor " + by + " can be found on the page. " + "Selection parameters: "
                + parameterMap);
    }
}

From source file:com.mkl.websuites.command.OperationOnWebElementTest.java

License:Apache License

@Test
public void shouldRunForTagName(@Mocked final WebDriver browser) {
    runFor(browser, "tagName", "someTagName", By.tagName("someTagName"));
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckHeaderContainsCommand.java

License:Apache License

@Override
protected String getStringParam() {
    WebElement headElem;//  w  w  w.j  a  v  a  2s  . c o m
    try {
        headElem = browser.findElement(By.tagName("head"));
        return headElem.getAttribute("innerHTML");
    } catch (NoSuchElementException e) {
        return "";
    }
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckLinkHrefCommand.java

License:Apache License

@Override
protected String getStringParam() {

    try {/*from  w  ww.  j  a va2s.  co m*/
        List<WebElement> elements = browser.findElements(By.tagName("a"));
        for (WebElement elem : elements) {
            if (predicate(elem.getAttribute("href"))) {
                actualElement = elem;
                return "OK";
            }
        }
    } catch (NoSuchElementException e) {
        return null;
    }
    return null;
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckLinkTextMatchingCommand.java

License:Apache License

@Override
protected String getStringParam() {

    try {/*  w  w w.  j a  va 2 s  .c o m*/
        List<WebElement> elements = browser.findElements(By.tagName("a"));
        for (WebElement webElement : elements) {
            if (webElement.getText().matches(expectedLinkText)) {
                actualLinkText = webElement.getText();
                foundElem = webElement;
                return "OK";
            }
        }
    } catch (NoSuchElementException e) {
        return null;
    }
    return null;
}

From source file:com.moodle.testmanager.FormActions.java

License:GNU General Public License

/**
 * Enters a value in either of the two default text entry area plugins.
 * @param textEntryAreaID The ID of the text entry area.
 * @param message The message to enter in the field.
 * @throws Exception Throws a descriptive exception if the plugins are not available as this would imply that
 * <br/> a) The text area editor is broken.
 * <br/> b) Someone has changed something that has broken the test.
 * <br/> c) A third party plugin is implemented as the default text editor.
 *//*from w ww. j  a  v  a2s .  c  om*/
public void enterValueInTextArea(CharSequence message) throws Exception {
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    boolean itemVisible = false;
    boolean mceVisible = false;
    try {
        WebElement e = driver.findElementByTagName(TEXTAREA);
        itemVisible = e.isDisplayed();
        WebElement emce = driver.findElement(By.tagName(IFRAME));
        mceVisible = emce.isDisplayed();
    } catch (Exception e) {
    }
    if (itemVisible) {
        WebElement e = driver.findElementByTagName(TEXTAREA);
        e.sendKeys(message);
    } else if (mceVisible) {
        WebElement messagebox = driver.findElementByTagName(IFRAME);
        driver.switchTo().frame(messagebox);
        WebElement richTextBox = driver.findElement(By.id(TINYMCE));
        richTextBox.click();
        richTextBox.sendKeys(message);
        driver.switchTo().window(driver.getWindowHandle());
    } else {
        throw new Exception(exceptionNoTextEditor);
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.mroza.seleniumTests.EditProgramViewTests.EditProgramViewPage.java

License:Open Source License

public void inputTableName(String tableName) {
    WebElement table = getTableWithHeader("", true);
    WebElement tableHeader = table.findElement(By.className("ui-datatable-header"));
    tableHeader.findElement(By.tagName("input")).sendKeys(tableName);
    SeleniumWaiter.waitForJQueryAndPrimeFaces(driver);
}

From source file:com.mroza.seleniumTests.EditProgramViewTests.EditProgramViewPage.java

License:Open Source License

public void changeTableName(String tableName, String oldTableName) {
    WebElement table = getTableWithHeader(oldTableName, true);
    WebElement tableHeader = table.findElement(By.className("ui-datatable-header"));
    tableHeader.findElement(By.tagName("input")).clear();
    tableHeader.findElement(By.tagName("input")).sendKeys(tableName);
    SeleniumWaiter.waitForJQueryAndPrimeFaces(driver);
}

From source file:com.mroza.seleniumTests.EditProgramViewTests.EditProgramViewPage.java

License:Open Source License

public void changeTableRow(String tableName, String rowName, String oldRowName) {
    WebElement tableRow = getRowForTable(tableName, oldRowName, true);
    List<WebElement> tableRowColumns = tableRow.findElements(By.tagName("td"));
    tableRowColumns.get(0).findElement(By.tagName("input")).clear();
    tableRowColumns.get(0).findElement(By.tagName("input")).sendKeys(rowName);
}

From source file:com.mroza.seleniumTests.EditProgramViewTests.EditProgramViewPage.java

License:Open Source License

public void setUpTableContentHeader(String tableName, int teachingNumber, int generalizationNumber) {
    WebElement table = getTableWithHeader(tableName, true);
    WebElement tableContent = table.findElement(By.className("ui-datatable-tablewrapper"));
    WebElement tableContentHeader = tableContent.findElement(By.tagName("thead"));
    List<WebElement> tableContentHeaderColumns = tableContentHeader.findElements(By.className("checkbox-cell"));
    for (WebElement tableContentHeaderColumn : tableContentHeaderColumns) {
        if (tableContentHeaderColumn.findElement(By.className("ui-column-title")).getText().equals("U:")) {
            setUpHeaderParameter(tableContentHeaderColumn, teachingNumber);
        }/*from ww w  .  j  a  v a2  s. c  om*/
        if (tableContentHeaderColumn.findElement(By.className("ui-column-title")).getText().equals("G:")) {
            setUpHeaderParameter(tableContentHeaderColumn, generalizationNumber);
        }
    }

}