Test Overview
This test uses FluentWait with polling to wait for a button to become clickable on a web page. It verifies that the button can be clicked successfully.
This test uses FluentWait with polling to wait for a button to become clickable on a web page. It verifies that the button can be clicked successfully.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.FluentWait; import java.time.Duration; import java.util.NoSuchElementException; public class FluentWaitTest { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "path/to/chromedriver"); WebDriver driver = new ChromeDriver(); try { driver.get("https://example.com/dynamic_button"); FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(15)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class); WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("dynamicButton"))); button.click(); WebElement message = driver.findElement(By.id("message")); assert message.getText().equals("Button clicked!") : "Message text did not match expected value."; System.out.println("Test Passed: Button clicked and message verified."); } finally { driver.quit(); } } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open and ready | - | PASS |
| 2 | Navigates to https://example.com/dynamic_button | Page with dynamic button is loaded | - | PASS |
| 3 | Creates FluentWait with 15 seconds timeout and 2 seconds polling interval, ignoring NoSuchElementException | Wait object configured | - | PASS |
| 4 | Waits until button with id 'dynamicButton' is clickable | Button becomes clickable after some delay | Button is clickable | PASS |
| 5 | Clicks the button | Button clicked, page updates message | - | PASS |
| 6 | Finds element with id 'message' and verifies its text equals 'Button clicked!' | Message displayed on page | Message text equals 'Button clicked!' | PASS |
| 7 | Test ends and browser closes | Browser closed | - | PASS |