Example usage for org.openqa.selenium By xpath

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

Introduction

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

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.util.ByConverter.java

License:Open Source License

public static By convert(ElementLocatorType type, String locator) {
    By by = null;/*w w  w.  jav  a 2s .co  m*/

    if (type == ElementLocatorType.Id) {
        by = By.id(locator);
    } else if (type == ElementLocatorType.ClassName) {
        by = By.className(locator);
    } else if (type == ElementLocatorType.CssSelector) {
        by = By.cssSelector(locator);
    } else if (type == ElementLocatorType.LinkText) {
        by = By.linkText(locator);
    } else if (type == ElementLocatorType.Name) {
        by = By.name(locator);
    } else if (type == ElementLocatorType.TagName) {
        by = By.tagName(locator);
    } else if (type == ElementLocatorType.XPath) {
        by = By.xpath(locator);
    } else if (type == ElementLocatorType.Value) {
        by = By.xpath("//*[@value='" + locator + "']");
    } else {
        throw new BehaveException(message.getString("exception-invalid-option", type, "convert"));
    }

    return by;
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.SeleniumComponent.java

License:Apache License

@Override
public void loadByXPath(final String value) {
    this.locator = new Locator(Locator.LocatorType.XPATH, value);
    if (this.isDisplayed) {
        WebDriverWait wait = new WebDriverWait(getSeleniumWebDriver(), TIMEOUT);
        wait.until(ExpectedConditions.visibilityOf(getSeleniumWebDriver().findElement(By.xpath(value))));
        setXPath(value);/*from  w  w w . ja v  a  2s  . c  o m*/
        setElement(getSeleniumWebDriver().findElement(By.xpath(value)));
    }

}

From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.table.SeleniumCell.java

License:Apache License

/** 
 * Recover a cell from a given table by its coordinates.
 * @param table Table element /*w w w  .j  av a 2s .co m*/
 * @param coordinate coordinates of cell in the table
 */
public SeleniumCell(final WebElement table, final Coordinate coordinate, final CellType type) {

    validateCoordinate(coordinate);

    String xpath = "";

    switch (type) {
    case HEAD:
        xpath = ".//thead/tr[%d]/th[%d]";
        break;
    case BODY:
        xpath = ".//tbody/tr[%d]/td[%d]";
        break;
    case FOOT:
        xpath = ".//tfoot/tr[%d]/td[%d]";
        break;
    }

    String locator = String.format(xpath, coordinate.getLineIndex(), coordinate.getColumnIndex());

    this.cell = table.findElement(By.xpath(locator));
}

From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.table.SeleniumTable.java

License:Apache License

/**
 * Generic method to take line cells of a tbody, thead or tfoot structure and returns as a List<List<Cell>>.
 * @param type/*w  w  w  .j  a  va 2s  .c  o m*/
 * @return List<List<Cell>>
 */
private List<List<Cell>> getAllCellsByLine(CellType type) {

    String locatorLines = "", locatorColumn = "";

    switch (type) {
    case HEAD:
        locatorLines = ".//thead/tr";
        locatorColumn = ".//th";
        break;
    case BODY:
        locatorLines = ".//tbody/tr";
        locatorColumn = ".//td";
        break;
    case FOOT:
        locatorLines = ".//tfoot/tr";
        locatorColumn = ".//td";
        break;
    }

    List<WebElement> lines = this.getElement().findElements(By.xpath(locatorLines)); // Recover all lines from the table

    List<List<Cell>> cellLines = new ArrayList<List<Cell>>(); // List of lines of the table

    Integer lineIndex = 1;

    for (WebElement line : lines) { // iterate the lines taken from table

        List<Cell> cellColumns = new ArrayList<Cell>();
        List<WebElement> columns = line.findElements(By.xpath(locatorColumn)); // Recover all columns from the lines
        Integer columnIndex = 1;

        for (WebElement column : columns) { // iterate the columns taken from the line
            Cell cell = new SeleniumCell(column);
            cell.setCoordinates(lineIndex, columnIndex);
            cellColumns.add(cell);
            columnIndex++;
        } // end of columns iteration

        cellLines.add(cellColumns);
        lineIndex++;
    } // end of lines iteration

    return cellLines;
}

From source file:browsermator.com.DragAndDropAction.java

@Override
public void RunAction(WebDriver driver) {

    try {//from  w w  w.j a  va 2 s .  co  m

        WebElement dragElement = driver.findElement(By.xpath(this.Variable1));
        WebElement dropElement = driver.findElement(By.xpath(this.Variable2));

        Actions actions = new Actions(driver);
        actions.dragAndDrop(dragElement, dropElement).perform();

        this.Pass = true;
    } catch (Exception e) {
        this.Pass = false;
        System.out.println("Exception: " + e);

    }
}

From source file:browsermator.com.StoreLinkAsVarByXPATHAction.java

@Override
public void RunAction(WebDriver driver) {
    try {//from www  .j  a v a  2 s. c  o m

        String link_value = driver.findElement(By.xpath(this.Variable1)).getAttribute("href");

        SetStoredLinkHashValue(this.Variable2, link_value);

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

    }

}

From source file:browsermator.com.StoreLinksAsArrayByXPATHAction.java

@Override
public void RunAction(WebDriver driver) {
    try {// ww w  .ja  v a  2 s.  co  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:bst.cpo.automation.dm.actions.SystemOverview_Actions.java

public boolean Is_Enabled_Search_Button() {
    //<input type="submit" class="pure-button pure-button-primary" value="Search" ng-disabled="searchForm.$invalid">
    try {// w  ww. ja v a 2s .com
        WebElement element = DMDriver
                .findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div[2]/div[1]/div[1]/form/input[2]"));
        if (element.isEnabled()) {
            return true;
        }
        return false;
    } catch (Exception e) {
        logThis("Exception during test occurred : " + e.getMessage());
    }
    return false;
}

From source file:bst.cpo.automation.dm.actions.SystemOverview_Actions.java

public void Set_User(String strUser) {
    //<input type="text" ng-model="pp.query" maxlength="60" required="" class="ng-dirty ng-invalid ng-invalid-required">
    WebElement element = DMDriver/*from  w  w  w.  j a v a2 s . c  om*/
            .findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div[2]/div[1]/div[1]/form/input[1]"));
    element.click();
    element.clear();
    element.sendKeys(strUser);
}

From source file:bst.cpo.automation.dm.actions.SystemOverview_Actions.java

public void Search_Click() {
    //<input type="submit" class="pure-button pure-button-primary new-folder-btn" ng-disabled="groupForm.$invalid" value="Save and create" disabled="disabled">
    if (Is_Enabled_Search_Button()) {
        WebElement element = DMDriver/*from   w w  w  . j  a v  a2s.co m*/
                .findElement(By.xpath("//*[@id='app']/div/div[4]/div/div/div[2]/div[1]/div[1]/form/input[2]"));
        element.click();
    } else {
        logThis("Search_Click called and 'Search' button was not enabled.");
        Assert.fail("Search_Click called and 'Search' button was not enabled.");
    }
}