Fluent wait is not working

143 views
Skip to first unread message

garvitag...@gmail.com

unread,
Feb 8, 2019, 1:44:36 AM2/8/19
to Selenium Users
Hi,

 I have applied fluent wait to poll every 4 sec with timeout 60 sec to find an element. And refresh page everytime before finding element. Below is code :

 // Fluent wait until  task appears

        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(Duration
                .ofSeconds(60)).pollingEvery(Duration.ofSeconds(4)).ignoring(
                        NoSuchElementException.class);

        wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                System.out.println("in loop");
                driver.navigate().refresh();
                return driver.findElement(getLocator(
                        "dataCollectionTask_XPATH"));
            }
        });

Output : Apply method is executed only once, page gets refreshed and gives error element not found . It does not go in loop again. 

Please help me with understanding what have i missed here.

Thanks !!

Abhishek Sharma

unread,
Feb 8, 2019, 2:08:32 AM2/8/19
to seleniu...@googlegroups.com
Hi,

I never tried fluent wait facing some problem .....if possible try this it work for me.....


By loaderSpinner = By.xpath("");

maxRetryCount = 20

=========================================


if (checkElementPresence(loaderSpinner)) {

int retryCount = 0;

while (checkElementPresence(loaderSpinner) == true

&& retryCount < Integer.parseInt(props.getProperty("maxRetryCount"))) {

retryCount++;

}

}


=========================================


//Method to find presence of element

public static boolean checkElementPresence(By by){

try{

if (driver.findElements(by).size() != 0){

logger.info("The element is present "+by.toString());

return true;

}else{

logger.info("The element not present "+by.toString());

}


}catch (Exception e){

logger.error(e);

Assert.fail();

}return false;

}


=========================================




Thanks 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a0e2cee3-9714-401b-b4a8-0169cee0b16e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks & Regards

Abhishek Sharma (QA)
s2908abhishek (Skype)
Reply all
Reply to author
Forward
0 new messages