Java Code Examples for org.openqa.selenium.WebElement.findElement()

The following are Jave code examples for showing how to use findElement() of the org.openqa.selenium.WebElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: JTreeDynamicTreeTest.java   View Source Code Vote up 6 votes
public void editANodeWithEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    final WebElement root = tree.findElement(By.cssSelector(".::root"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    new WebDriverWait(driver, 3).until(new Function<WebDriver, Boolean>() {
        @Override public Boolean apply(WebDriver input) {
            return root.getText().equals("Hello World");
        }
    });
    AssertJUnit.assertEquals("Hello World", root.getText());
}
 
Example 2
Project: ToDoMVCEmberJS   File: BasicTodoMvcPage.java   View Source Code Vote up 6 votes
@Step("Rreactivate the item")
public boolean reActivateItem(String itemName){
    WebElement todoItem = driver.findElement(By.xpath("//label[.='" + itemName + "']"));
    WebElement divClass = todoItem.findElement(By.xpath(".."));
    WebElement chkComplete = divClass.findElement(By.tagName("input"));
    chkComplete.click();
    WebElement liClass = null;
    try{
        liClass = divClass.findElement(By.xpath(".//*[@id='clear-completed']"));
        if (liClass.isDisplayed()){
            return false;
        }
    }catch (Exception e){
    }
    return true;
}
 
Example 3
Project: marathonv5   File: JTreeDynamicTreeTest.java   View Source Code Vote up 6 votes
public void expandTree() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("false", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(root, "expanded", "true"));
    AssertJUnit.assertEquals("true", root.getAttribute("expanded"));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    new Actions(driver).doubleClick(node1).perform();
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Child 1", node2.getText());
    WebElement node3 = tree.findElement(By.cssSelector(".::nth-node(4)"));
    AssertJUnit.assertEquals("Child 2", node3.getText());
    WebElement node4 = tree.findElement(By.cssSelector(".::nth-node(5)"));
    AssertJUnit.assertEquals("Parent 2", node4.getText());
    new Actions(driver).doubleClick(node4).perform();
    WebElement node5 = tree.findElement(By.cssSelector(".::nth-node(6)"));
    AssertJUnit.assertEquals("Child 1", node5.getText());
    WebElement node6 = tree.findElement(By.cssSelector(".::nth-node(7)"));
    AssertJUnit.assertEquals("Child 2", node6.getText());
}
 
Example 4
Project: marathonv5   File: JavaDriverTest.java   View Source Code Vote up 6 votes
public void findElementsByCSSWithSelfSelector() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("text-field"));
    WebElement element2 = element1.findElement(By.cssSelector("."));
    AssertJUnit.assertEquals(element1, element2);
    WebElement element3 = element1.findElement(By.cssSelector(".:enabled"));
    AssertJUnit.assertEquals(element1, element3);
    WebElement element4 = element1.findElement(By.cssSelector(".#text-field"));
    AssertJUnit.assertEquals(element1, element4);
    List<WebElement> none = element1.findElements(By.cssSelector(".#text-fieldx"));
    AssertJUnit.assertEquals(0, none.size());
}
 
Example 5
Project: satisfy   File: BaseTableSteps.java   View Source Code Vote up 5 votes
@Override
public void inTableClickOnIdentityInRowsWithParameters(By elementIdentity, ExamplesTable params) {
    List<WebElement> matchedRows = getMatchedRows(params);
    if (matchedRows.isEmpty()) {
        throw new AssertionError("You should define at list one existing " +
                "record value");
    }
    for (WebElement matchedRow : matchedRows) {
        WebElement elementToClick = matchedRow.findElement
                (elementIdentity);
        webPage.clickOn(elementToClick);
    }
}
 
Example 6
Project: selenium-testng-template   File: SeleniumUtils.java   View Source Code Vote up 5 votes
/**
 * Example: getRowTextsByColumnText(table, 2, '22') returns row {11, 22, 33}
    * 1	2	3
    * 11	22	33
    * 111	222	333
 * 
 * @param table
 * @param columnIndex Start from 1
 * @param searchText
 * @return
 */
public static final List<String> getTableRowByColumnText(WebElement table, int columnIndex, String searchText) {
	if (!table.getTagName().equalsIgnoreCase("table")) {
   		throw new IllegalArgumentException("Table web element is required");
   	}

	WebElement rowElement = table.findElement(By.xpath("//tr//td[position()=" + columnIndex + " and contains(*|text(), '" + searchText + "')]/.."));
   	List<WebElement> elements = rowElement.findElements(By.tagName("td"));
   	List<String> result = new ArrayList<String>(elements.size());
   	for (WebElement e : elements) {
   		result.add(StringUtils.trim(e.getText()));
   	}
   	return result;
}
 
Example 7
Project: marathonv5   File: JTreeDynamicTreeTest.java   View Source Code Vote up 5 votes
public void getNodesByRow() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals(1 + "", tree.getAttribute("rowCount"));
    new Actions(driver).doubleClick(root).perform();
    new WebDriverWait(driver, 3).until(hasAttributeValue(tree, "rowCount", 3 + ""));
    AssertJUnit.assertEquals(3 + "", tree.getAttribute("rowCount"));
    WebElement node1 = tree.findElement(By.cssSelector(".::nth-node(2)"));
    AssertJUnit.assertEquals("Parent 1", node1.getText());
    WebElement node2 = tree.findElement(By.cssSelector(".::nth-node(3)"));
    AssertJUnit.assertEquals("Parent 2", node2.getText());
}
 
Example 8
Project: marathonv5   File: JTreeDynamicTreeTest.java   View Source Code Vote up 5 votes
public void nodeEditor() throws Throwable {
    System.err.println("Ignore the following NPE. The DynamicTree class has a bug");
    WebElement tree = page.getTree();
    tree.click();
    WebElement root = tree.findElement(By.cssSelector(".::nth-node(1)"));
    AssertJUnit.assertEquals("Root Node", root.getText());
    WebElement editor = root.findElement(By.cssSelector(".::editor"));
    editor.clear();
    editor.sendKeys("Hello World", Keys.ENTER);
    root.submit();
    AssertJUnit.assertEquals("Hello World", root.getText());
}
 
Example 9
Project: marathonv5   File: JavaDriverTest.java   View Source Code Vote up 5 votes
public void findElementOfElement() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element = driver.findElement(By.name("box-panel"));
    AssertJUnit.assertNotNull(element);
    WebElement clickMe = element.findElement(By.name("click-me"));
    AssertJUnit.assertNotNull(clickMe);
}
 
Example 10
Project: mot-automated-testsuite   File: WebDriverWrapper.java   View Source Code Vote up 5 votes
/**
 * Clicks the specified link found by locating the starting text then following the relative XPath expression.
 * @param startTag          The tag containing the starting text
 * @param startText         The starting text
 * @param relativeXPath     The relative XPath expression
 */
public void clickLink(String startTag, String startText, String relativeXPath) {
    WebElement startingTextElement = webDriver.findElement(
            By.xpath("//" + startTag.toLowerCase() + "[contains(text(),'" + startText + "')]"));
    WebElement link = startingTextElement.findElement(By.xpath(relativeXPath + ".//a"));
    clickAndWaitForPageLoad(link);
}
 
Example 11
Project: marathonv5   File: JTableRenderTest.java   View Source Code Vote up 5 votes
public void getCellEditorCombobox() throws Throwable {
    driver = new JavaDriver();
    WebElement comboCell = driver.findElement(By.cssSelector("table::mnth-cell(1,3)"));
    AssertJUnit.assertEquals("Snowboarding", comboCell.getText());
    WebElement comboCellEditor = driver.findElement(By.cssSelector("table::mnth-cell(1,3)::editor"));
    AssertJUnit.assertEquals("combo-box", comboCellEditor.getTagName());
    WebElement option = comboCellEditor.findElement(By.cssSelector(".::all-options[text='Knitting']"));
    // Needs the click to put in editing mode
    // comboCell.click();
    option.click();
    AssertJUnit.assertEquals("Knitting", comboCell.getText());
}
 
Example 12
Project: marathonv5   File: JTableColumnSelectionTest.java   View Source Code Vote up 5 votes
private void clickOnCol(WebElement table, int colNum) {
    // Index on the element is 1 based and index on the JTable is 0 based.
    // Hence adding 1 to the colNum
    WebElement col = table.findElement(By.cssSelector(".::mnth-cell(1," + (colNum + 1) + ")"));
    col.click();
    table.sendKeys(Keys.NULL);
}
 
Example 13
Project: marathonv5   File: JTableRowSelectionTest.java   View Source Code Vote up 5 votes
private void clickOnRow(WebElement table, int rowNum) {
    // Index on the element is 1 based and index on the JTable is 0 based.
    // Hence adding 1 to the rowNum
    WebElement row = table.findElement(By.cssSelector(".::mnth-cell(" + (rowNum + 1) + ",3)"));
    row.click();
    table.sendKeys(Keys.NULL);
}
 
Example 14
Project: mot-automated-testsuite   File: WebDriverWrapper.java   View Source Code Vote up 5 votes
/**
 * Clicks the specified link found by locating the starting text then following the relative XPath expression.
 * @param startTag          The tag containing the starting text
 * @param startText         The starting text
 * @param relativeXPath     The relative XPath expression
 * @param linkText          The link text to look for below the relative expression
 */
public void clickLink(String startTag, String startText, String relativeXPath, String linkText) {
    WebElement startingTextElement = webDriver.findElement(
            By.xpath("//" + startTag + "[contains(text(),'" + startText + "')]"));
    WebElement link = startingTextElement.findElement(
            By.xpath(relativeXPath + ".//a[contains(text(),'" + linkText + "')]"));
    clickAndWaitForPageLoad(link);
}
 
Example 15
Project: marathonv5   File: JSplitPaneTest.java   View Source Code Vote up 5 votes
public void getLeftRightComponents() throws Throwable {
    driver = new JavaDriver();
    WebElement splitPaneLeft = driver.findElement(By.cssSelector("split-pane::left"));
    splitPaneLeft.findElement(By.cssSelector("list"));
    WebElement splitPaneTop = driver.findElement(By.cssSelector("split-pane::top"));
    AssertJUnit.assertEquals(splitPaneTop, splitPaneLeft);
    WebElement splitPaneRight = driver.findElement(By.cssSelector("split-pane::right"));
    WebElement splitPaneBottom = driver.findElement(By.cssSelector("split-pane::bottom"));
    AssertJUnit.assertEquals(splitPaneBottom, splitPaneRight);
}
 
Example 16
Project: module-template   File: Unit1Helper.java   View Source Code Vote up 4 votes
private void initUnit1ModificationById(int id) {
    WebElement checkbox = driver.findElement(By.cssSelector(String.format("input[value='%s']", id)));
    WebElement row = checkbox.findElement(By.xpath("./../.."));
    List<WebElement> cells = row.findElements(By.tagName("td"));
    cells.get(7).findElement(By.tagName("a")).click();
}
 
Example 17
Project: selenium-camp-17   File: ProductBasePage.java   View Source Code Vote up 4 votes
private WebElement relativeOf(final WebElement rootElement, final By childElement) {
	return rootElement.findElement(childElement);
}
 
Example 18
Project: marathonv5   File: JTableRowSelectionTest.java   View Source Code Vote up 4 votes
private void shiftClickOnRow(WebElement table, int rowNum) {
    WebElement anotherRow = table.findElement(By.cssSelector(".::mnth-cell(" + (rowNum + 1) + ",3)"));
    new Actions(driver).keyDown(Keys.SHIFT).click(anotherRow).perform();
    table.sendKeys(Keys.NULL);
}
 
Example 19
Project: Java_Good   File: ContactHelper.java   View Source Code Vote up 4 votes
public void initContactModificationById(int id) {
    WebElement checkbox = wd.findElement(By.cssSelector("input[value='" + id + "']"));
    WebElement contactRow = checkbox.findElement(By.xpath("./../../."));
    contactRow.findElement(By.xpath(".//img[@title='Edit']")).click();
}
 
Example 20
Project: mot-automated-testsuite   File: WebDriverWrapper.java   View Source Code Vote up 3 votes
/**
 * Get the text within the specified element, found by locating the starting text then following the relative XPath
 * expression.
 * @param startTag          The tag containing the starting text
 * @param startText         The starting text
 * @param relativeXPath     The relative XPath expression
 * @return The text
 */
public String getElementText(String startTag, String startText, String relativeXPath) {
    WebElement startingElement = webDriver.findElement(
            By.xpath("//" + startTag.toLowerCase() + "[contains(text(),'" + startText + "')]"));
    WebElement relativeElement = startingElement.findElement(By.xpath(relativeXPath));
    return relativeElement.getText();
}