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

David542
  • 104,438
  • 178
  • 489
  • 842
  • Possible duplicate of [How to wait until the page is loaded with Selenium for Python?](https://stackoverflow.com/questions/26566799/how-to-wait-until-the-page-is-loaded-with-selenium-for-python) – JeffC Jul 09 '18 at 20:33
  • Specifically see: https://stackoverflow.com/a/30385843/2386774 – JeffC Jul 09 '18 at 20:34

1 Answers1

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())
PixelEinstein
  • 1,713
  • 1
  • 8
  • 17
  • 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 https://stackoverflow.com/questions/26566799/how-to-wait-until-the-page-is-loaded-with-selenium-for-python/30385843#30385843 – JeffC Jul 09 '18 at 20:35