plaidshirt
plaidshirt

Reputation: 5671

FluentWait doesn't wait by elementToBeClickable() method

I use following code to wait while page is loaded.

   Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(40, SECONDS)
            .pollingEvery(10, SECONDS)
            .ignoring(NoSuchElementException.class);

    wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(webelements.labelForInputFileField)));
    log.info("Page loaded!");

It doesn't work, I get following error:

java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:96) at org.openqa.selenium.support.ui.FluentWait.(FluentWait.java:87)

I tried with presenceOfElementLocated() method too, but same error. Requested page is loaded, I see it visually in browser.

Upvotes: 0

Views: 1804

Answers (2)

Mikhail
Mikhail

Reputation: 665

  1. java.lang.NullPointerException - This exception usually indicates that smthn is null, make sure that variables driver and webelements are set by the time you're executing this method.
  2. Make sure you're not using Guava version that is not compatible with your current framework

Upvotes: 1

Shubham Jain
Shubham Jain

Reputation: 17553

Try below FluentWait code :-

WebElement waitsss(WebDriver driver, By elementIdentifier){
     Wait<WebDriver> wait =
                new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
                                                 .pollingEvery(1, TimeUnit.SECONDS)
                                                 .ignoring(NoSuchElementException.class);

        return wait.until(new Function<WebDriver, WebElement>()
                {
                    public WebElement apply(WebDriver driver) {
                           return driver.findElement(elementIdentifier);
                    }
                });
}

if still not work. check your XPath. It may be your XPATH is invalid and so FluentWait throw expection

Another thing is that FluentWaitand Explicit wait are two different type of waits. You can't mix with another

For Explicit wait use below code :

WebDriverWait wait = new WebDriverWait(ad, 100);
wait.until(ExpectedConditions.elementToBeClickable(By.id("gst")).sendKeys(username);

refer below:-

http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/

OR Use JavascriptExecutor

WebElement Searchelement=driver.findElement("Your locator");
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", Searchelement);

Hope it will help you :)

Upvotes: 2

Related Questions