from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.wait import FluentWait
import time
# Setup WebDriver (Chrome example)
driver = webdriver.Chrome()
try:
driver.get('https://example.com/dynamic_loading') # Replace with actual test URL
# Click the button to start loading hidden element
start_button = driver.find_element(By.ID, 'startButton')
start_button.click()
# Setup Fluent Wait: timeout 15 seconds, polling every 1 second
wait = WebDriverWait(driver, 15, poll_frequency=1, ignored_exceptions=[NoSuchElementException])
# Wait until the hidden element is visible
hidden_element = wait.until(EC.visibility_of_element_located((By.ID, 'hiddenElement')))
# Assert the element is displayed
assert hidden_element.is_displayed(), 'Hidden element should be visible after wait'
finally:
driver.quit()This script opens the test page and clicks the button that triggers loading of a hidden element.
It uses Selenium's WebDriverWait with a polling interval of 1 second and a timeout of 15 seconds to implement a Fluent Wait.
The wait ignores NoSuchElementException during polling to avoid failing early.
Once the hidden element is visible, the script asserts it is displayed.
Finally, the browser is closed to clean up.