Monday, March 27, 2017

splinter wait page to load

class wait_for_page_load(object):

    def __init__(self, browser):
        self.browser = browser

    def __enter__(self):
        self.old_page = self.browser.find_element_by_tag_name('html')

    def page_has_loaded(self):
        new_page = self.browser.find_element_by_tag_name('html')
        return new_page.id != self.old_page.id

    def __exit__(self, *_):
        wait_for(self.page_has_loaded)

with wait_for_page_load(browser):
    browser.find_element_by_link_text('my link').click()

No comments:

Post a Comment