David542
David542

Reputation: 110312

WebDriverWait on javascript value

How would I accomplish the following in python's selenium:

el = WebDriverWait(self.driver, 10).until(
        expected_conditions.js_return_value(
          ("return document.readyState === 'complete' ? true : false")
        )
     )

I've seen ways to do the above in Java, but cannot find a similar solution in python

Upvotes: 1

Views: 161

Answers (1)

PixelEinstein
PixelEinstein

Reputation: 1733

I did something similar but used the __call__ class function to get the same effect, like this:

class DynamicLoadState:
    def __call__(self, driver):
        LoadComplete = False
        if driver.execute_script("return document.readyState") == 'complete': LoadComplete = True
        return LoadComplete

WebDriverWait(self.driver, 10).until(DynamicLoadState())

Upvotes: 1

Related Questions