Skip to content

Instantly share code, notes, and snippets.

@kennethkoontz
Created August 7, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kennethkoontz/3287959 to your computer and use it in GitHub Desktop.
Save kennethkoontz/3287959 to your computer and use it in GitHub Desktop.
nextpage
def nextPage(self):
"""Continue to the next page.
IE is notorious for not registering click events. Let's make sure when
we go to the next page the state has changed.
Try 3 times. With a second of elapsed time between each try.
"""
initial = self.surveyState.getHTMLAttribute('value')
self.contBtn.click()
current = self.surveyState.getHTMLAttribute('value')
attempts = 0
while True:
if initial != current:
break
elif attempts >= 3:
break
self.contBtn.click()
time.sleep(1)
attempts += 1
@SethAThomas
Copy link

CONTINUE_TRIES = 3
SLEEP = 1 # in seconds

def clickBtn(self, btn, isSuccessful, tries=1, delay=SLEEP):
'''click a button; allows X tries before it fails'''

assert tries > 0, "number of tries must be greater than 0"

attempts = 0

while 1:
    btn.click()
    attempts += 1

    if isSuccessful(self):
        break
    if attempts >= tries:
        raise Exception('button failed to click within the defined number of tries')
    time.sleep(delay)

def clickContinueBtn(self):
'''click the continue button'''

def getSuccessFn():
    original = self.surveyState.getHTMLAttribute('value')
    def isSuccessful(instance):
        return original == instance.surveyState.getHTMLAttribute('value')
    return isSuccessful

self.clickBtn(self.contBtn, getSuccessFn(), tries=CONTINUE_TRIES)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment