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

The following examples show how to use org.openqa.selenium.WebElement#isDisplayed() . 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: AddUserFormValidationTest.java    From product-iots with Apache License 2.0 6 votes vote down vote up
@Test(description = "Test for short user name")
public void shortUserNameTest() {
    clearForm();

    firstNameField.sendKeys(Constants.User.Add.FIRST_NAME);
    lastNameField.sendKeys(Constants.User.Add.LAST_NAME);
    emailField.sendKeys(Constants.User.Add.EMAIL);
    userNameField.sendKeys(Constants.User.Add.SHORT_USER_NAME);

    addUserButton.click();

    WebElement alert = driver.findElement(By.xpath(
            uiElementMapper.getElement("iot.admin.addUser.formError.xpath")));

    if (!alert.isDisplayed()) {
        Assert.assertTrue(false, "Alert for short user name is not displayed.");
    }

    Assert.assertEquals(alert.getText(), Constants.User.Add.SHORT_USER_NAME_ERROR_MSG);
}
 
Example 2
Source File: InstructorFeedbackResultsPage.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks if the body of all the results panels are collapsed or expanded.
 * @param isVisible true to check for expanded, false to check for collapsed.
 * @return true if all results panel body are equals to the visibility being checked.
 */
private boolean isAllResultsPanelBodyVisibilityEquals(boolean isVisible) {
    By panelCollapseSelector = By.cssSelector(".panel-heading+.panel-collapse");
    List<WebElement> webElements = browser.driver.findElements(panelCollapseSelector);
    int numOfQns = webElements.size();

    assertTrue(numOfQns > 0);

    for (WebElement e : webElements) {
        if (e.isDisplayed() != isVisible) {
            return false;
        }
    }

    return true;
}
 
Example 3
Source File: LoginFormValidationTest.java    From product-iots with Apache License 2.0 5 votes vote down vote up
@Test(description = "Test for incorrect username")
public void incorrectUserNameTest() throws Exception {
    clearForm();
    userNameField.sendKeys(Constants.User.Login.WRONG_USER_NAME);
    passwordField.sendKeys(automationContext.getSuperTenant().getTenantAdmin().getPassword());
    loginButton.click();

    WebElement alert = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath")));
    if (alert.isDisplayed()) {
        Assert.assertEquals(alert.getText(), Constants.User.Login.FAILED_ERROR);
    } else {
        Assert.assertTrue(false, Constants.ALERT_NOT_PRESENT);
    }

}
 
Example 4
Source File: LoginFormValidationTest.java    From product-iots with Apache License 2.0 5 votes vote down vote up
@Test(description = "Test for incorrect password")
public void incorrectPasswordTest() throws Exception {
    clearForm();
    userNameField.sendKeys(automationContext.getSuperTenant().getTenantAdmin().getPassword());
    passwordField.sendKeys(Constants.User.Login.WRONG_USER_PASSWORD);
    loginButton.click();

    WebElement alert = driver.findElement(By.xpath(uiElementMapper.getElement("iot.user.login.incorrect.xpath")));
    if (alert.isDisplayed()) {
        Assert.assertEquals(alert.getText(), Constants.User.Login.FAILED_ERROR);
    } else {
        Assert.assertTrue(false, Constants.ALERT_NOT_PRESENT);
    }
}
 
Example 5
Source File: RegistrationFormValidationTest.java    From product-iots with Apache License 2.0 5 votes vote down vote up
@Test(description = "Test for submitting an empty registration form")
public void emptyFormTest() throws IOException {
    registerPage.validateForm("", "", "", "", "", "");

    WebElement alertFirstName = driver.findElement(By.id(
            uiElementMapper.getElement("iot.user.register.form.error")));

    if (!alertFirstName.isDisplayed()) {
        Assert.assertTrue(false, "Alert for first name is not displayed");
    }

    Assert.assertEquals(alertFirstName.getText(), "Firstname is a required field. It cannot be empty.");
}
 
Example 6
Source File: InstructorStudentRecordsPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if the bodies of all the record panels are collapsed or expanded.
 * @param isVisible true to check for expanded, false to check for collapsed.
 * @return true if all record panel bodies are equals to the visibility being checked.
 */
private boolean areAllRecordPanelBodiesVisibilityEquals(boolean isVisible) {
    for (WebElement e : getStudentFeedbackPanels()) {
        if (e.isDisplayed() != isVisible) {
            return false;
        }
    }

    return true;
}
 
Example 7
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public boolean isMenuQnNumberVisible(int qnNumber) {
    if (qnNumber != NEW_QUESTION_NUM) {
        WebElement selectQuestionNumberDropdown =
                browser.driver.findElement(By.id(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER + "-" + qnNumber));
        return selectQuestionNumberDropdown.isDisplayed();
    }

    WebElement retrievedQnTable = browser.driver.findElement(By.id("questionTable-" + qnNumber));
    return retrievedQnTable.findElement(By.id(Const.ParamsNames.FEEDBACK_QUESTION_NUMBER)).isDisplayed();
}
 
Example 8
Source File: BestMatchBy.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Best element is selected as follows:
 * Take the first displayed element without any elements on top of it,
 * if none: take first displayed, or
 * if none are displayed: just take the first.
 * @param context context used to find the elements.
 * @param elements elements found, from which the best must be selected.
 * @return 'best' element from elements.
 */
public static WebElement selectBestElement(SearchContext context, List<WebElement> elements) {
    JavascriptExecutor jse = JavascriptHelper.getJavascriptExecutor(context);
    WebElement element = elements.get(0);
    WebElement firstDisplayed = null;
    WebElement firstOnTop = null;
    if (!element.isDisplayed() || !isOnTop(jse, element)) {
        for (int i = 1; i < elements.size(); i++) {
            WebElement otherElement = elements.get(i);
            if (otherElement.isDisplayed()) {
                if (firstDisplayed == null) {
                    firstDisplayed = otherElement;
                }
                if (isOnTop(jse, otherElement)) {
                    firstOnTop = otherElement;
                    element = otherElement;
                    break;
                }
            }
        }
        if (firstOnTop == null
                && firstDisplayed != null
                && !element.isDisplayed()) {
            // none displayed and on top
            // first was not displayed, but another was
            element = firstDisplayed;
        }
    }
    return element;
}
 
Example 9
Source File: BrowserTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
@WaitUntil(TimeoutPolicy.STOP_TEST)
public boolean waitForVisibleIn(String place, String container) {
    Boolean result = Boolean.FALSE;
    WebElement element = getElementToCheckVisibility(place, container);
    if (element != null) {
        scrollIfNotOnScreen(element);
        result = element.isDisplayed();
    }
    return result;
}
 
Example 10
Source File: StaleElementUtils.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if is element stale.
 *
 * @param e
 *            the e
 * @return true, if is element stale
 */
public static boolean isElementStale(final WebElement e) {
	try {
		e.isDisplayed();
		return false;
	} catch (final StaleElementReferenceException ex) {
		return true;
	}
}
 
Example 11
Source File: ValueOfBy.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
@Override
public WebElement findElement(SearchContext context) {
    WebElement element = super.findElement(context);
    if (element != null) {
        WebElement nested = ConstantBy.nestedElementForValue().findElement(element);
        if (nested != null && nested.isDisplayed()) {
            element = nested;
        }
    }
    return element;
}
 
Example 12
Source File: BaseUI.java    From movieapp-dialog with Apache License 2.0 5 votes vote down vote up
/**
 * isVisible - Checks whether the given locator matches a visible WebElement
 * @param locator The locator for the element
 * @return true if the element is found and visible
 */
public boolean isVisible(String locator) {
	boolean found = false;
       try{
           WebElement element = findElement(locator);
           if(element.isDisplayed()){
           	logger.info("INFO: Element " + locator + " found and is visible");
           	found = true;
           }
       }catch (NoSuchElementException err){
       	//Ignore
       }
       return found;
}
 
Example 13
Source File: BrowserService.java    From collect-earth with MIT License 5 votes vote down vote up
public void clickOnElements(RemoteWebDriver driver, String cssSelector) {
	final List<WebElement> dataLayerVisibility = driver.findElementsByCssSelector(cssSelector);
	for (final WebElement webElement : dataLayerVisibility) {
		if (webElement.isDisplayed()) {
			webElement.click();
		}
	}
}
 
Example 14
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean verifyNewRankRecipientsQuestionFormIsDisplayed() {
    WebElement contribForm = browser.driver.findElement(By.id("rankRecipientsForm"));
    return contribForm.isDisplayed() && addNewQuestionButton.isDisplayed();
}
 
Example 15
Source File: AbstractSubmarineIT.java    From submarine with Apache License 2.0 4 votes vote down vote up
protected boolean waitForParagraph(final int paragraphNo, final String state) {
  By locator = By.xpath(getParagraphXPath(paragraphNo)
      + "//div[contains(@class, 'control')]//span[2][contains(.,'" + state + "')]");
  WebElement element = pollingWait(locator, MAX_PARAGRAPH_TIMEOUT_SEC);
  return element.isDisplayed();
}
 
Example 16
Source File: IAndroidUtils.java    From carina with Apache License 2.0 4 votes vote down vote up
/**
 * Scrolls into view in specified container
 * 
 * @param scrollToEle
 *            - has to be id, text, contentDesc or className
 * @param scrollableContainer
 *            - ExtendedWebElement type
 * @param containerSelectorType
 *            - has to be id, text, textContains, textStartsWith, Description,
 *            DescriptionContains or className
 * @param containerInstance
 *            - has to an instance number of desired container
 * @param eleSelectorType
 *            - has to be id, text, textContains, textStartsWith, Description,
 *            DescriptionContains or className
 * @param eleSelectorInstance
 *            - has to an instance number of desired container
 * @return ExtendedWebElement
 *         <p>
 *         example of usage: ExtendedWebElement res =
 *         AndroidUtils.scroll("News", newsListContainer,
 *         AndroidUtils.SelectorType.CLASS_NAME, 1,
 *         AndroidUtils.SelectorType.TEXT, 2);
 **/
default public ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer,
        SelectorType containerSelectorType, int containerInstance, SelectorType eleSelectorType,
        int eleSelectorInstance) {
    ExtendedWebElement extendedWebElement = null;
    long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
    // TODO: support multi threaded WebDriver's removing DriverPool usage
    WebDriver drv = castDriver();

    // workaorund for appium issue: https://github.com/appium/appium/issues/10159
    if (scrollToEle.contains(",")) {
        scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);
        if (eleSelectorType.equals(SelectorType.TEXT)) {
            eleSelectorType = SelectorType.TEXT_CONTAINS;
        }
    }

    for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {

        try {
            By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable("
                    + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ".instance("
                    + containerInstance + "))" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")"
                    + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ".instance("
                    + eleSelectorInstance + "))");

            WebElement ele = drv.findElement(scrollBy);
            if (ele.isDisplayed()) {
                UTILS_LOGGER.info("Element found!!!");
                extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
                break;
            }
        } catch (NoSuchElementException noSuchElement) {
            UTILS_LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle),
                    noSuchElement);
        }

        for (int j = 0; j < i; j++) {
            checkTimeout(startTime);
            MobileBy.AndroidUIAutomator(
                    "new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType)
                            + ".instance(" + containerInstance + ")).scrollForward()");
            UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
        }
    }

    return extendedWebElement;
}
 
Example 17
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean verifyNewNumScaleQuestionFormIsDisplayed() {
    WebElement mcqForm = browser.driver.findElement(By.id("numScaleForm"));
    return mcqForm.isDisplayed() && addNewQuestionButton.isDisplayed();
}
 
Example 18
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean verifyNewConstSumQuestionFormIsDisplayed() {
    WebElement constSumForm = browser.driver.findElement(By.id("constSumForm"));
    return constSumForm.isDisplayed() && addNewQuestionButton.isDisplayed();
}
 
Example 19
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean verifyNewRankOptionsQuestionFormIsDisplayed() {
    WebElement contribForm = browser.driver.findElement(By.id("rankOptionsForm"));
    return contribForm.isDisplayed() && addNewQuestionButton.isDisplayed();
}
 
Example 20
Source File: AndroidUtils.java    From carina with Apache License 2.0 4 votes vote down vote up
/** Scrolls into view in specified container
   * @param scrollToEle - has to be id, text, contentDesc or className
   * @param scrollableContainer - ExtendedWebElement type
   * @param containerSelectorType - container Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
   *                             or className
   * @param eleSelectorType -  scrollToEle Selector type: has to be id, text, textContains, textStartsWith, Description, DescriptionContains
   *                             or className
   * @return ExtendedWebElement
   * <p>
   * example of usage:
   * ExtendedWebElement res = AndroidUtils.scroll("News", newsListContainer, AndroidUtils.SelectorType.CLASS_NAME,
   *                          AndroidUtils.SelectorType.TEXT);
   **/
  public static ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType,
                        SelectorType eleSelectorType){
      ExtendedWebElement extendedWebElement = null;
      long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
// TODO: support multi threaded WebDriver's removing DriverPool usage
WebDriver drv = getDriver();

      //workaorund for appium issue: https://github.com/appium/appium/issues/10159
      if (scrollToEle.contains(",")) {
          scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","),
                  ",", 0, 2);
          if (eleSelectorType.equals(SelectorType.TEXT)) {
              eleSelectorType = SelectorType.TEXT_CONTAINS;
          }
      }

      for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {

          try {
		By scrollBy = MobileBy.AndroidUIAutomator(
				"new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType)
						+ ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView("
						+ getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");
		
              WebElement ele = drv.findElement(scrollBy);
              if (ele.isDisplayed()) {
                  LOGGER.info("Element found!!!");
                  extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
                  break;
              }
          } catch (NoSuchElementException noSuchElement) {
              LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
          }

          for (int j = 0; j < i; j++) {
              checkTimeout(startTime);
              MobileBy.AndroidUIAutomator("new UiScrollable(" +
                      getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");
              LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
          }
      }

      return extendedWebElement;
  }