Created
August 15, 2012 21:34
-
-
Save kennethkoontz/3363896 to your computer and use it in GitHub Desktop.
looping construct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locator = '.ui-dialog' | |
timeout = 10 | |
try: | |
for x in range(timeout): | |
self.wd.find_element_by_css_selector(locator) | |
time.sleep(1) | |
raise TimeoutException('%r still present after %s seconds' % (locator, timeout)) | |
except NoSuchElementException: | |
pass |
What are you trying to accomplish? It looks like you are testing for something to be removed.
timeout is a misleading name. Generally, that means how long you are going to pause something. timeout => maxTries
timeout and sleep time should be customizable. 10 and 1 might be the defaults you want.
Should be a function.
If you unroll the loop, you'll see that there is an unnecessary sleep at the end. Pretend we are going to try 3 times:
find(locator)
sleep(1)
find(locator)
sleep(1)
find(locator)
sleep(1) // unnecessary, since we aren't testing anymore
This also means that something only has 9 seconds to be removed, not the 10 that you think.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Couple things to keep in mind. 'find_element_by_css_selector(locator) will raise no Such Element exception when element is not found.