Robotframework: Clicking web-elemnt in loop often fails to find an element
<p>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.</p>

<p>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?</p>

<pre><code>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())&lt;=start_time+wait_interval:
            if int(time()) &gt;= 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)
</code></pre>

<p>Shouldn't be using the keywords <code>Wait Until Page Contains Element</code> or <code>Wait Until Element Is Visible</code> of the <a href="http://robotframework.org/Selenium2Library/Selenium2Library.html" rel="nofollow">Selenium2Library</a> for this purpose:</p>

<pre><code>*** Test cases ***
Your Test Case
  Prerequisite steps
  Wait Until Page Contains Element  ${locator}
  Succeeding steps
</code></pre>

<p><strong>Edit:</strong> Below is what your Python code might look like in pure Robot syntax.</p>

<pre><code>${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}
</code></pre>

python selenium robotframework