Reputation: 13
I have created a keyword for RF and Selenium2Library. It is supposed to wait for some element by clicking periodically on some other element which will renew the area where the element is supposed to appear. I use it for example for waiting for mails in postbox.
The problem is that pretty often the "renew element" cannot be found and clicked on some loop iteration however it exists on the screenshot. Any ideas why it can happen?
def check_if_element_appeared(self, element_locator, renew_locator, renew_interval=10, wait_interval=300):
if not self.is_visible(renew_locator):
raise AssertionError("Error Message")
start_time=int(time())
scan_time = start_time
if not self.is_visible(element_locator):
while int(time())<=start_time+wait_interval:
if int(time()) >= scan_time + renew_interval:
scan_time = int(time())
self.click_element(renew_locator)
if self.is_visible(element_locator):
break
if not self.is_visible(element_locator):
raise AssertionError("Error Message")
self._info("Message")
else:
self._info("Current page contains element '%s'." % element_locator)
Upvotes: 1
Views: 1057
Reputation: 5902
Shouldn't be using the keywords Wait Until Page Contains Element
or Wait Until Element Is Visible
of the Selenium2Library for this purpose:
*** Test cases ***
Your Test Case
Prerequisite steps
Wait Until Page Contains Element ${locator}
Succeeding steps
Edit: Below is what your Python code might look like in pure Robot syntax.
${iteration}= Evaluate ${wait_interval} / ${renew_interval}
: FOR ${i} IN RANGE 0 ${iteration}
\ Click Element ${renew_locator}
\ Sleep 1
\ ${is_visible}= Run Keyword And Return Status Element Should Be Visible ${element_locator}
\ Exit For Loop If ${is_visible}
\ Run Keyword If '${is_visible}' == 'False' Sleep ${renew_interval}
Click Element ${element_locator}
Upvotes: 1