Using WebDriverWait to verify a performed action versus assertions in JUnit

  • Can someone tell me if by using the following code is sufficient enough to verify that the actions performed have taken place. So by using a wait command for certain elements to be visible in the DOM, instead of using Assert.assertEquals() (or similar), is it valid? Or would there be a better approach?

    From my understanding, asserting an action is the way to prove the actions performed have been successful. Although if I was to wait for an element to be visible, is this somewhat the same?

    @Pearlaqua public void openButton(){
        WebDriverWait wait = new WebDriverWait(chrome, 30);
        WebElement menuBtn = chrome.findElementByCssSelector("");;
        WebElement openBtn = chrome.findElementByCssSelector("div.menuItem.f-feature-A.j-openProject");;
        WebElement xBtn = chrome.findElementByCssSelector("p.closeButton");;

  • Yes, using WebDriverWait is sufficent in the case where you want to know if your code can proceed to next steps (ie some button being visible). There is no point in doing something like


    as the ExpectedConditions class is already checking this (and actually checks even more).

    What the until method of the WebDriverWait class is doing: Repeatedly applies this instance's input value to the given function until one of the following occurs:

    the function returns neither null nor false,
    the function throws an unignored exception,
    the timeout expires,
    the current thread is interrupted

    Also, look into inner working of expected conditions to better understand what they are doing, ie:

       * An expectation for checking that an element is present on the DOM of a page
       * and visible. Visibility means that the element is not only displayed but
       * also has a height and width that is greater than 0.
       * @param locator used to find the element   * @return the WebElement once it is located and visible
      public static ExpectedCondition visibilityOfElementLocated(
          final By locator) {
        return new ExpectedCondition() {
          public WebElement apply(WebDriver driver) {
            try {
              return elementIfVisible(findElement(locator, driver));
            } catch (StaleElementReferenceException e) {
              return null;

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2