Actually I am working on one script in my application there I need to wait till its complete the execution, once complete the execute it will change the status. But I don't know when the execution completes (Dynamic time).

This is web-based application and I am not sure which wait or feature or method I need to use to wait until it satisfy the condition. Below is the sample code I tried (Can not post exact code).

Please suggest me how to proceed with or any suggestion on this.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.FluentWait;

import com.google.common.base.Function;

public class TestingClass {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.gecko.driver", "D:\\SeleniumClass\\src\\libs\\geckodriver.exe");
         WebDriver driver = new FirefoxDriver();
         FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
         Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>()
         public Boolean apply(WebDriver arg0) {
         WebElement element = arg0.findElement(By.id("tabButton"));
         String type = element.getAttribute("type");
         System.out.println("The type is " + type);
         return true;
         return false;
  • 3
    Let us know how it went after 5 hours. :D
    – Mate Mrše
    Commented Apr 22, 2021 at 13:15
  • 2
    @MateMrše: Will see if anyone reply.
    – Selenium
    Commented Apr 22, 2021 at 14:35
  • Upvote for this @Selenium
    – forumqaa
    Commented Apr 22, 2021 at 14:51

2 Answers 2


The Selenium Webdriver has all kinds of timeouts, waiting for 5 hours isnt going to work like this. I might try something like:

  1. Start browser with WebDriver and do some actions
  2. Quit browsers
  3. Create a while loop that waits a while (e.g. sleep a couple of minutes), then starts the a NEW browser, check if done, if not quit browser and repeat wait.

e.g. dont use Selenium todo the waiting, but your code and keep building a new session and use it only for a short while


Explicit wait is already available for most cases:

WebDriverWait explicit = new WebDriverWait(driver,Duration.ofHours(5));

you can use expected conditions in that :


if you want to use special condition then use :

package test_suites;

import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import Utils.excelParcer;
import driversetup.TestBaseClass;
import page_objects.homepage;

public class Testcase1 extends TestBaseClass {

    homepage homepage;
    WebDriver driver;

    @Test(description = "Test case 1 assert True")
    public void loginPageTitleTest2() {
        EdgeOptions options = new EdgeOptions();
        // options.setBinary("C:\\Program Files
        // (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
        options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        options.addArguments("disable-infobars"); // disabling infobars
        options.addArguments("--disable-extensions"); // disabling extensions
        options.addArguments("--disable-gpu"); // applicable to windows os only
        System.setProperty("webdriver.edge.driver", "C:\\Users\\prave\\Downloads\\msedgedriver.exe");

        driver = new EdgeDriver(options);
        FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
        WebDriverWait explicit = new WebDriverWait(driver, Duration.ofHours(5));

        wait.until(this.attributeContains(By.xpath("//button"), "type", "button"));

    public void tearDown() {

    static ExpectedCondition<Boolean> attributeContains(final By locator, final String attribute, final String value) {
        return new ExpectedCondition<Boolean>() {
            private String currentValue = null;

            public Boolean apply(WebDriver driver) {
                return driver.findElement(locator).getAttribute(attribute) == value;

            public String toString() {
                return String.format("value found by %s to contain \"%s\". Current value: \"%s\"", locator, value,


Note: attributeContains is already available in selenium expected condition the code is just to show you how to create your on fluent wait and expected condition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.