Example usage for org.openqa.selenium WebElement getAttribute

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

Introduction

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

Prototype

String getAttribute(String name);

Source Link

Document

Get the value of the given attribute of the element.

Usage

From source file:browsermator.com.StoreLinksAsArrayByXPATHAction.java

@Override
public void RunAction(WebDriver driver) {
    try {/*  ww w  .ja  va  2 s  . c o m*/

        ArrayList<String> link_list = new ArrayList();
        List<WebElement> link_elements = driver.findElements(By.xpath(this.Variable1));
        for (Iterator<WebElement> it = link_elements.iterator(); it.hasNext();) {
            WebElement e = it.next();
            String thishref = e.getAttribute("href");
            if (link_list.contains(thishref)) {

            } else {
                link_list.add(thishref);
            }
        }

        SetStoredLinkArray(link_list);

        this.Pass = true;
    } catch (NoSuchElementException e) {
        this.Pass = false;

    }

}

From source file:ca.nrc.cadc.search.integration.AbstractSearchFormPage.java

License:Open Source License

void enterInputValue(final WebElement inputElement, final String value) throws Exception {
    final String inputID = inputElement.getAttribute("id");

    summonTooltip(inputID);/*from w  w  w.  ja  v a2s . com*/
    showInputField(inputID);
    waitForElementVisible(inputElement);

    for (int i = 0; i < value.length(); i++) {
        inputElement.sendKeys(Character.toString(value.charAt(i)));
        waitFor(150L);
    }

    closeTooltip();
}

From source file:ca.nrc.cadc.search.integration.CAOMSearchFormPage.java

License:Open Source License

int findDataTrainValueIndex(final By menuLocator, final String value, final boolean ignoreCase)
        throws Exception {
    final Select selectMenu = new Select(dataTrain.findElement(menuLocator));
    final List<WebElement> options = selectMenu.getOptions();
    final int optionSize = options.size();

    for (int i = 0; i < optionSize; i++) {
        final WebElement option = options.get(i);
        final String optionValue = option.getAttribute("value");

        if ((ignoreCase && optionValue.equalsIgnoreCase(value)) || optionValue.equals(value)) {
            return i;
        }// w  w  w. ja v a  2s  . co  m
    }

    throw new IllegalStateException(
            "No such element with value '" + value + "' (Case" + (ignoreCase ? " " : " not ") + "ignored)");
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public String togglePublicAttributeForRow(int rowNum) throws Exception {
    String currentPermission = "";
    WebElement editIcon = find(xpath("//span[contains(@class, 'glyphicon-edit')]"));
    editIcon.click();//from  w  ww.j a  v a2 s .  c o  m
    WebElement permissionCheckbox = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.elementToBeClickable(By.id("publicPermission")));

    currentPermission = permissionCheckbox.getAttribute("checked");
    click(permissionCheckbox);
    clickButton(SAVE);

    // confirm folder delete
    if (isJqiMsgShowing(SUCCESSFUL)) {
        clickButton(OK);
    } else {
        throw new Exception("Permissions editing not successful for row : " + rowNum);
    }

    return currentPermission;
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

private boolean isDisabled(WebElement webEl) {
    return webEl.getAttribute("class").contains("disabled");
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public boolean isFileSelectedMode(int rowNumber) {
    // Class of selected row is different:
    // visually it will be different, but for now the change
    // in css class is enough to check
    //*[@id="beacon"]/tbody/tr[1]
    WebElement selectedRow = beaconTable.findElement(xpath("//*[@id=\"beacon\"]/tbody/tr[" + rowNumber + "]"));

    if (!selectedRow.getAttribute("class").contains("selected")) {
        return false;
    }/*from   w  ww .ja v  a 2s  .c o m*/

    // Behaviour is different if person is logged in or not
    if (isLoggedIn()) {
        if (!(isDisabled(deleteButton) && isDisabled(downloadButton))) {
            return true;
        }
    } else { // There will need to be a check for publicly available for download or not?
        if (isDisabled(deleteButton) && !isDisabled(downloadButton)) {
            return true;
        }
    }

    return false;
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public boolean isDefaultSort() {
    // Name column asc is default sort when page loads
    WebElement nameColHeader = beaconTable.findElement(
            xpath("//*[@id=\"beacon_wrapper\"]/div[2]/div/div[1]/div[1]/div/table/thead/tr/th[2]"));

    if (nameColHeader.getAttribute("class").equals("sorting_asc")) {
        return true;
    }/*  w  ww  .  j  av  a 2  s . co  m*/

    return false;
}

From source file:cc.kune.selenium.PageObject.java

License:GNU Affero Public License

/**
 * Checks if is present./*  www .j  a va2  s  .  c  o m*/
 * 
 * @param element
 *          the element
 * @return true, if is present
 */
public boolean isPresent(final WebElement element) {
    // FIXME: find a better way to do this
    try {
        getWebDriver().findElement(By.id(element.getAttribute("id")));
        return true;
    } catch (final NoSuchElementException e) {
        return false;
    }
}

From source file:cc.kune.selenium.PageObject.java

License:GNU Affero Public License

/**
 * Wait for.//www .j a v a 2  s .co  m
 * 
 * @param element
 *          the element
 */
public void waitFor(final WebElement element) {
    final String id = element.getAttribute("id");
    // LOG.info("WAIT FOR: " + id);
    waitFor(id, new Runnable() {
        @Override
        public void run() {
            Assert.assertTrue(element.isDisplayed());
        }
    });
}

From source file:cc.kune.selenium.SeleniumUtils.java

License:GNU Affero Public License

/**
 * Hightlight.//  w  ww  .  java 2  s .co  m
 * 
 * @param element
 *          the element
 * @param webdriver
 *          the webdriver
 */
public static void hightlight(final WebElement element, final WebDriver webdriver) {
    SeleniumUtils.showCursor(webdriver, element);
    sleep(300);
    if (TextUtils.notEmpty(element.getAttribute("id"))) {
        final String script = "window.jQuery('#" + element.getAttribute("id") + "').addClass('k-outline');"
                + "setTimeout('window.jQuery(\"#" + element.getAttribute("id")
                + "\").removeClass(\"k-outline\")', 1200);";
        // Antes 700
        // LOG.info("High: " + script);
        jsExec(webdriver).executeScript(script);
    }
}