I am using Selenium (python) to test a web application. However, sometimes a line of code triggers an error cause the first line didn't have time enough to run. For instance:
...
driver.find_element_by_id("form_widget_date").click()
driver.find_element_by_link_text(str(self.day)).click()
...
As a result, the second line (sometimes) woudn't find the link_text because Selenium, apparently, does not have time to finish the first line. The error does not occur when I put a sleep between the lines.
My question is: Is there a way to automatically wait a bit longer for each line of code instead of solving it like this:
...
time.sleep(2)
driver.find_element_by_id("form_widget_date").click()
time.sleep(2)
driver.find_element_by_link_text(str(self.day)).click()
time.sleep(2)
...
?