As the title suggests need to wait for dynamically loaded material. The material shows when scrolling to the end of the page each time.
Currently trying to do this by the following:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located(
(By.XPATH, "//*[@id='inf-loader']/span[1][contains(@style, 'display: inline-block')]")))
Is the xpath the problem here (not all that familiar)? It keeps timing out even though the display style does change when scrolling with selenium.
Selenium: Waiting Until the Element Is Visiblevar wait = new WebDriverWait(driver, TimeSpan. FromSeconds(20)); As you can see, we give the WebDriverWait object two parameters: the driver itself and a TimeSpan object that represents the timeout for trying to locate the element.
How can I ask the Selenium-WebDriver to wait for few seconds in Java? To tell the Selenium WebDriver to wait for a specified amount of time use Thread. sleep. This will tell Java to pause execution of the test for the specified number of milliseconds.
This can be achieved with synchronization in Selenium. We shall add an explicit wait criteria where we shall stop or wait till the element no longer exists. Timeout exception is thrown once the explicit wait time has elapsed and the expected behavior of the element is still not available on the page.
I would wait for the display
style to change to inline-block
with a custom Expected Condition and use value_of_css_property()
:
from selenium.webdriver.support import expected_conditions as EC
class wait_for_display(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
try:
element = EC._find_element(driver, self.locator)
return element.value_of_css_property("display") == "inline-block"
except StaleElementReferenceException:
return False
Usage:
wait = WebDriverWait(driver, 5)
wait.until(wait_for_display((By.XPATH, "//*[@id='inf-loader']/span[1]")))
You may also try to tweak the poll frequency to make it check the condition more often:
wait = WebDriverWait(driver, 5, poll_frequency=0.1) # default frequency is 0.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With