-
Notifications
You must be signed in to change notification settings - Fork 18
Selenium Tips and Tricks
aethemba edited this page Oct 21, 2014
·
6 revisions
Avoid Time.sleep()
Avoid the use of time.sleep() and, instead, explicitly wait for an action or system change. For example, wait for an element to show. You can use something like this for the waiting. First check the element presence. Next, check if the element is visible:
- Check if the element is present -->
self.assertTrue(self.browser.is_element_present_by_css('selector', wait_time=5))
. Looks if the element is present somewhere on the page. - Check if the element is visible -->
self.assertTrue(self.is_visible('selector'))
. The is_visible method looks for the display:none style tag.
- Disclaimer: Sometimes it just doesn't seem to work. For example, see this thread: https://code.google.com/p/selenium/issues/detail?id=2766 None of the causes seem to be consistent nor are the remedies. The only thing I've found to consistently solve the issues is a time.sleep().
**IntegrityErrors **
This is not really a Selenium issue but we came across this several times. Whenever you run into errors of the form: IntegrityError: duplicate key value violates unique constraint <table_name>
, use the SQLite 3 database for testing. I'm unsure what's causing the issue with a Postgres testing database but switching to SQLite at least allows you to continue work.