1

Below is my code

public boolean waitForElementToBeClickable(String xpathValue){

        Boolean flag = false;
        WebElement myDynamicElement = (new WebDriverWait(Base.base.getDriver(), 30))
                  .until(ExpectedConditions.elementToBeClickable(By.xpath(xpathValue)));
        flag = true;
        return flag;

    }

This wait for element to appear for 30 sec and if element is ready before 30 sec it perform the next command.

but when I use below code for fluent wait

public Boolean waitForElementToAppear(final WebElement e){

         Wait<WebElement> wait = new FluentWait<WebElement>(e)
                 .withTimeout(30, TimeUnit.SECONDS)              
                 .pollingEvery(2, TimeUnit.SECONDS)
                 ;

         Boolean foo = wait.until(new Function<WebElement, Boolean>() {
             public Boolean apply( WebElement element) {

               return element.isDisplayed();
             }
           });
        return foo;
         }

It says No-such Element exception, it doesn't even wait for 30 sec, it throw exception instantly.

Can someone tell what is the issue with it ?

Oomph Fortuity
  • 5,710
  • 10
  • 44
  • 89
  • See [this](http://stackoverflow.com/questions/28658418/differences-between-impilicit-explicit-and-fluentwait) – Saifur Mar 04 '15 at 12:23
  • possible duplicate of [selenium webdriver - explicit wait vs implicit wait](http://stackoverflow.com/questions/10404160/selenium-webdriver-explicit-wait-vs-implicit-wait) – olyv Mar 06 '15 at 11:56

1 Answers1

0

Usually when you use a FluentWait you would have to ignore, at least, the NoSuchElementException during the waiting.

Like this:

Wait<WebElement> wait = new FluentWait<WebElement>(e)
             .withTimeout(30, TimeUnit.SECONDS)              
             .pollingEvery(2, TimeUnit.SECONDS)
             .ignoring(NoSuchElementException.class);
Morvader
  • 2,317
  • 3
  • 31
  • 44
  • If I use ignore the test passes but in actiual it should not as element has not been clicked. – Abhinav Rajput Mar 04 '15 at 12:58
  • I dont know you test code, could you share it?, anyway, your code is waiting for the element to be visible "return element.isDisplayed();" not clickable. You should modify your condition if you want an equivalent wait. – Morvader Mar 04 '15 at 13:07