Example usage for org.openqa.selenium WebElement isDisplayed

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

Introduction

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

Prototype

boolean isDisplayed();

Source Link

Document

Is this element displayed or not?

Usage

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.
 *//*  www  . j  av a  2  s . c o  m*/
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.moodle.testmanager.FormActions.java

License:GNU General Public License

/**
 * Handles a checkbox that you want to tick. If it is ticked then leave it ticked, if it is not ticked then tick it.
 * This is particularly useful for admin pages where a change may have already been made to the checkbox state.
 * @param fieldID The ID tag of the field yo want to be checked.
 *///from   w  w w  .  j  a  v  a  2  s.  c o m
public void handleCheckboxStateAndEnterTick(String fieldID) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement tick = driver.findElement(By.xpath(".//*[@id='" + fieldID + "'][@checked='checked']"));
        itemVisible = tick.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
    } else {
        WebElement unTicked = driver.findElement(By.xpath(".//*[@id='" + fieldID + "']"));
        unTicked.click();
    }
}

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

License:GNU General Public License

/**
 * Intelligently navigates to a tree menu to an item that is 2 levels deep. 
 * @param level1 The Xpath locator for the top level parent node in the tree.
 * @param level2 The Xpath locator for the second level parent node in the tree.
 *///w  ww.j av a 2  s .  co  m
public void navigateTree2DeepByXpath(String level1, String level2) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement e = driver.findElement(By.xpath(level2));
        itemVisible = e.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement level2Element = driver.findElement(By.xpath(level2));
        level2Element.click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    } else {
        WebElement level1Element = driver.findElement(By.xpath(level1));
        level1Element.click();
        WebElement level2Element = driver.findElement(By.xpath(level2));
        level2Element.click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
}

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

License:GNU General Public License

/**
 * Intelligently navigates to a tree menu to an item that is 3 levels deep. 
 * @param level1 The Xpath locator for the top level parent node in the tree.
 * @param level2 The Xpath locator for the second level parent node in the tree.
 * @param level3 The Xpath locator for the third level parent node in the tree.
 *///w w w. j ava2  s.  c om
public void navigateTree3DeepByXpath(String level1, String level2, String level3) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement e = driver.findElement(By.xpath(level3));
        itemVisible = e.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement level3Element = driver.findElement(By.xpath(level3));
        level3Element.click();
    } else {
        WebElement level1Element = driver.findElement(By.xpath(level1));
        level1Element.click();
        WebElement level2Element = driver.findElement(By.xpath(level2));
        level2Element.click();
        WebElement level3Element = driver.findElement(By.xpath(level3));
        level3Element.click();
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

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

License:GNU General Public License

/**
 * Intelligently navigates to a tree menu to an item that is 4 levels deep e.g. "Add a new user". 
 * @param level1 The Xpath locator for the top level parent node in the tree e.g. "Site administration".
 * @param level2 The Xpath locator for the second level parent node in the tree e.g. "Users".
 * @param level3 The Xpath locator for the third level parent node in the tree e.g. "Browse list of users".
 * @param level4 The Xpath locator for the fourth level parent node in the tree e.g. "Add a new user".
 *///from  w w w. ja va2  s.c  om
public void navigateTree4DeepByXpath(String level1, String level2, String level3, String level4) {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement e = driver.findElement(By.xpath(level4));
        itemVisible = e.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement level4Element = driver.findElement(By.xpath(level4));
        level4Element.click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    } else {
        WebElement level1Element = driver.findElement(By.xpath(level1));
        level1Element.click();
        WebElement level2Element = driver.findElement(By.xpath(level2));
        level2Element.click();
        WebElement level3Element = driver.findElement(By.xpath(level3));
        level3Element.click();
        WebElement level4Element = driver.findElement(By.xpath(level4));
        level4Element.click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
}

From source file:com.moodle.testmanager.pageObjectModel.Assignment.java

License:GNU General Public License

/**
 * Clicks the Edit my submission button.
 */// ww w . ja v a2  s.c  o m
public void clickButtonAddOrEditSubmission() {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement button = driver.findElementByCssSelector(
                "input[value='" + this.properties.get("buttonEditMySubmission") + "']");
        itemVisible = button.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement button = driver.findElementByCssSelector(
                "input[value='" + this.properties.get("buttonEditMySubmission") + "']");
        button.click();
    } else {
        WebElement submitButton = driver.findElementByCssSelector("input[value='Add submission']");
        submitButton.click();
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.AssignmentAddSubmission.java

License:GNU General Public License

/**
 * Clicks the submission statement checkbox. Test will not fail with a No Such Element Exception but will continue to next step.
 */// w  w  w .  j av a 2 s.  c  om
public void clickCheckboxSubmissionStatement() {
    boolean itemVisible = false;
    try {
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        WebElement checkbox = driver.findElementById("id_submissionstatement");
        itemVisible = checkbox.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement checkbox = driver.findElementById("id_submissionstatement");
        checkbox.click();
    } else {
    }
}

From source file:com.moodle.testmanager.pageObjectModel.AssignmentGrading.java

License:GNU General Public License

/**
 * Clicks the Grade link/*  ww  w. j ava 2  s . c  o  m*/
 */
public void clickLinkGrade(String studentFirstName, String studentSurname) {
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    boolean studentVisible = false;
    try {
        WebElement link = driver.findElementByXPath(
                "//tr[contains(.,'" + studentFirstName + " " + studentSurname + "')]/td/a/*[@title='Grade']");
        studentVisible = link.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    ;
    if (studentVisible) {
        WebElement link = driver.findElementByXPath(
                "//tr[contains(.,'" + studentFirstName + " " + studentSurname + "')]/td/a/*[@title='Grade']");
        link.click();
    } else {
        WebElement next = driver.findElementByLinkText("Next");
        next.click();
        clickLinkGrade(studentFirstName, studentSurname);
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.Courses.java

License:GNU General Public License

/**
 * Clicks the Add a New Course Button. If there are no courses already it does this from the home page. If there is already a course
 * the page object locates an alternative Add a new course button.
 *//* w  w  w  . j a v a2s.c o m*/
public void clickAddCourse() {
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    boolean itemVisible = false;
    try {
        WebElement addCourseButton = driver.findElement(
                By.cssSelector("input[value='" + this.properties.get("addNewCourseButton") + "']"));
        itemVisible = addCourseButton.isDisplayed();
    } catch (NoSuchElementException ex) {
    }
    if (itemVisible) {
        WebElement addCourseButton = driver.findElement(
                By.cssSelector("input[value='" + this.properties.get("addNewCourseButton") + "']"));
        addCourseButton.click();
    } else {
        //WebElement courseTreeItemRoot = driver.findElement(By .partialLinkText(this.properties.get("coursesNavBlock")));
        WebElement courseTreeItemRoot = driver
                .findElement(By.partialLinkText(this.properties.get("coursesNavBlock")));
        courseTreeItemRoot.click();
        WebElement addCourseButton = driver.findElement(
                By.cssSelector("input[value='" + this.properties.get("addNewCourseButton") + "']"));
        addCourseButton.click();
    }
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.moodle.testmanager.pageObjectModel.ForumPosts.java

License:GNU General Public License

/**
 * Deletes all forum posts(discussions) within any forum and returns to the Moodle home page when it is done.
 * Manage timeouts has to be set to 0 otherwise the catching the thrown exception slows the test down. Rest the driver timeout when
 * the loop is complete.//from w  w  w .  j av  a2s.c o  m
 */
public void deleteAllForumPosts() {
    boolean itemVisible = true;
    try {
        //Set driver time out to 0. This prevents the caught exception from slowing down the test.
        //TODO find out how to reset the timeout back to it's original value.
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
        while (itemVisible) {
            WebElement firstDiscussion = driver
                    .findElement(By.xpath(".//tr[@class='discussion r0']/td[@class='topic starter']/a"));
            itemVisible = firstDiscussion.isDisplayed();
            firstDiscussion.click();
            WebElement deleteLink = driver
                    .findElement(By.xpath("//a[contains(.,'" + this.properties.get("deleteLink") + "')]"));
            deleteLink.click();
            WebElement continueButton = driver
                    .findElement(By.xpath("//input[@value='" + this.properties.get("continueButton") + "']"));
            continueButton.click();
        }
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    } catch (NoSuchElementException ex) {
        BlockNavigation navigate = new BlockNavigation(driver);
        navigate.clickHome();
    }
}