How to use with wait for element
Closed this issue · 2 comments
Hi,
I have an element and a wait command like this
email_address_field = InputField(By.ID, "id_username")
WebDriverWait(self,30).until(expected_conditions.presence_of_element_located(self.email_address_field))
How to make it works?
Kind regards,
Frank Vu
Hey Frank,
I actually added wait support earlier this month -- I just forgot to document it. I'll be sure to do that soon :)
email_address_field = InputField(
By.ID,
'id_username',
wait=EC.presence_of_element_located,
wait_timeout=30)
This can be pretty tedious to specify for all of your elements, though, so it might make sense to create a class that defaults to something that makes sense for your tests.
from selenium.webdriver.support import expected_conditions as EC
import page_elements
class InputField(page_elements.InputField):
"""Extend `page_elements.InputField` to provide defaults to
`wait` and `wait_timeout`.
"""
def __init__(self, *args, **kwargs):
wait = kwargs['wait']
wait_timeout = kwargs['wait_timeout']
kwargs['wait'] = \
wait if wait is not None \
else EC.presence_of_element_located
kwargs['wait_timeout'] = \
wait_timeout if wait_timeout is not None else 30
# in the case you're using Python 2, you'll have to update this super call
# or update to Python 3 :)
super().__init__(*args, **kwargs)
I haven't run that, so you may need to tweak it a bit.
If you want to call WebDriverWait
you need to pass in the by
and selector
members of the element to your chosen wait function since WebDriverWait
doesn't support taking in a page element object as an argument. You should be able to do this:
WebDriverWait(driver, 30).until(EC.presence_of_element_located(
email_address_field.by, email_address_field.selector
))
Again, I haven't run this, so it might involve a bit of tweaking.
Let me know if these solutions works for you.
I'm going to go ahead and close this for now. Feel free to reopen if that doesn't work for you.