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

The following examples show how to use org.openqa.selenium.WebElement#findElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JTreeDynamicTreeTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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 2
Source File: InstructorFeedbackEditPageUiTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
private void assertEnabledVisibilityOptionsIncludesOnly(List<FeedbackParticipantType> expectedTypes,
                                                        int questionNumber) {
    Set<String> expectedEnabledOptions = new HashSet<>();
    for (FeedbackParticipantType expectedType : expectedTypes) {
        expectedEnabledOptions.add(expectedType.toString());
    }

    Set<String> actualEnableOptions = new HashSet<>();
    WebElement optionsTable = browser.driver.findElement(By.id("visibilityOptions-" + questionNumber));
    List<WebElement> enabledRows =
            optionsTable.findElements(By.cssSelector("tr:not([style='display: none;'])"));
    // remove the header row
    enabledRows.remove(0);
    for (WebElement enabledRow : enabledRows) {
        WebElement checkbox = enabledRow.findElement(By.cssSelector("input"));
        actualEnableOptions.add(checkbox.getAttribute("value"));
    }

    assertEquals(expectedEnabledOptions, actualEnableOptions);
}
 
Example 3
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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 4
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void clickRemoveMcqOptionLink(int optionIndex, int qnIndex) {
    String idSuffix = getIdSuffix(qnIndex);

    WebElement mcqOptionRow = browser.driver.findElement(By.id("mcqOptionRow-" + optionIndex + idSuffix));
    WebElement removeOptionLink = mcqOptionRow.findElement(By.id("mcqRemoveOptionLink"));
    click(removeOptionLink);
}
 
Example 5
Source File: TestApplicationListUtil.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Type should be 'shared' for shared and 'unique' for total.
 */
private int getEffortPoints(String applicationName, String type)
{
    WebElement applicationRow = getApplicationRow(applicationName);
    if (applicationRow == null)
        return -1;

    String xpath = "./div[contains(@class, 'stats')]/div[contains(@class, 'effortPoints') and contains(@class, '" + type + "')]";
    WebElement pointsSectionElement = applicationRow.findElement(By.xpath(xpath));

    WebElement effortPointsElement = pointsSectionElement.findElement(By.cssSelector(".points"));

    return Integer.parseInt(effortPointsElement.getText());
}
 
Example 6
Source File: InstructorCopyFsToModal.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Populates the fields of the form by using the provided name, and selecting every course.
 * @param newFsName feedback session name of the new session
 */
public void fillFormWithAllCoursesSelected(String newFsName) {
    WebElement fsCopyModal = browser.driver.findElement(By.id("fsCopyModal"));
    List<WebElement> coursesCheckBoxes = fsCopyModal.findElements(By.name(Const.ParamsNames.COPIED_COURSES_ID));
    for (WebElement e : coursesCheckBoxes) {
        markCheckBoxAsChecked(e);
    }

    WebElement fsNameInput = fsCopyModal.findElement(By.id(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME));
    fillTextBox(fsNameInput, newFsName);
}
 
Example 7
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void clickRemoveMsqOptionLink(int optionIndex, int qnIndex) {
    String idSuffix = getIdSuffix(qnIndex);

    WebElement msqOptionRow = browser.driver.findElement(By.id("msqOptionRow-" + optionIndex + idSuffix));
    WebElement removeOptionLink = msqOptionRow.findElement(By.id("msqRemoveOptionLink"));
    click(removeOptionLink);
}
 
Example 8
Source File: TestJavaApplicationOverviewUtil.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private WebElement getFileRowElement(String appSection, String filePath)
{
    WebElement fileTable = getAppSectionElement(appSection).findElement(By.xpath("../../div[contains(@class,'panel-body')]/table"));

    WebElement fileRow = fileTable.findElement(By
                .xpath("./tbody/tr/td/a[normalize-space(text()) = '" + filePath + "']/../.."));
    return fileRow;
}
 
Example 9
Source File: ExistsMatcher.java    From matchers-java with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSafely(WebElement element) {
    try {
        element.findElement(By.xpath("self::*"));
    } catch (WebDriverException e) {
        return false;
    }
    return true;
}
 
Example 10
Source File: TestApplicationListUtil.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the list of application names on the application list.
 */
public List<String> getApplicationNames()
{
    List<String> result = new ArrayList<>();

    List<WebElement> appInfoElements = getDriver().findElements(By.cssSelector(".appInfo"));
    for (WebElement appInfoRow : appInfoElements)
    {
        WebElement filename = appInfoRow.findElement(By.cssSelector(".fileName"));
        if (filename != null && filename.getText() != null)
            result.add(filename.getText().trim());
    }

    return Collections.unmodifiableList(result);
}
 
Example 11
Source File: AbstractPage.java    From oxTrust with MIT License 5 votes vote down vote up
protected void enableCheckBox(String checkBoxClassName) {
	WebElement checkBox = webDriver.findElement(By.className(checkBoxClassName));
	WebElement parent = checkBox.findElement(By.xpath(".."));
	if (!parent.getAttribute("class").contains("checked")) {
		parent.click();
	}
	Assert.assertTrue(parent.getAttribute("class").contains("checked"));
}
 
Example 12
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public void clickRemoveConstSumOptionLink(int optionIndex, int qnIndex) {
    String idSuffix = getIdSuffix(qnIndex);

    WebElement msqOptionRow = browser.driver.findElement(By.id("constSumOptionRow-" + optionIndex + idSuffix));
    WebElement removeOptionLink = msqOptionRow.findElement(By.id("constSumRemoveOptionLink"));
    click(removeOptionLink);
}
 
Example 13
Source File: OAuthGrantPage.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public List<String> getDisplayedGrants() {
    List<String> table = new LinkedList<>();
    WebElement divKcOauth = driver.findElement(By.id("kc-oauth"));
    for (WebElement li : divKcOauth.findElements(By.tagName("li"))) {
        WebElement span = li.findElement(By.tagName("span"));
        table.add(span.getText());
    }
    return table;
}
 
Example 14
Source File: FindIndexLeafNode.java    From find with MIT License 4 votes vote down vote up
FindIndexLeafNode(final WebElement element) {
    container = element;
    checkbox = new FindIndexCheckbox(element.findElement(By.tagName("span")));
}
 
Example 15
Source File: InstructorCourseEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getSectionLevelPanelBody(int instrNum, int sectionLevelIndex) {
    WebElement sectionPanel = getSectionLevelPanel(instrNum, sectionLevelIndex);
    return sectionPanel.findElement(By.cssSelector("div[class='panel-body']"));
}
 
Example 16
Source File: InstructorCourseDetailsPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getViewLink(int studentNum) {
    WebElement studentRow = browser.driver.findElement(By.id("student-c0." + studentNum));
    return studentRow.findElement(By.cssSelector("td.no-print.align-center > a:nth-child(1)"));
}
 
Example 17
Source File: InstructorSearchPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private WebElement getEditLink(String rowId) {
    WebElement studentRow = browser.driver.findElement(By.id("student-c" + rowId));
    return studentRow.findElement(By.cssSelector("td.no-print.align-center > a:nth-child(2)"));
}
 
Example 18
Source File: SmartWebElement.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public WebElement findElement(By by) {
    WebElement e = getElement();
    return e.findElement(by);
}
 
Example 19
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public void fillNumOfEntitiesToGiveFeedbackToBoxForNewQuestion(String num) {
    WebElement questionForm = browser.driver.findElement(By.id("form_editquestion-" + NEW_QUESTION_NUM));
    WebElement numberOfRecipients = questionForm.findElement(By.className("numberOfEntitiesBox"));
    fillTextBox(numberOfRecipients, num);
}
 
Example 20
Source File: BlamesTableRow.java    From warnings-ng-plugin with MIT License 2 votes vote down vote up
/**
 * Returns the child WebElement representing a link.
 *
 * @param parent
 *         the WebElement which is a parent of the link to be searched for
 *
 * @return the WebElement representing the link
 */
private WebElement findLink(final WebElement parent) {
    return parent.findElement(A_TAG);

}