1

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

2

1 Answer 1

1

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())
Sign up to request clarification or add additional context in comments.

1 Comment

This is more complicated than it needs to be... all you need is return driver.execute_script("return document.readyState") == 'complete'. You can remove the lines before and after your if statement. See stackoverflow.com/questions/26566799/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.