How to combine wait_util and do_until

23 views
Skip to first unread message

brandt...@gmail.com

unread,
Mar 5, 2014, 7:26:29 PM3/5/14
to wtfra...@googlegroups.com
Is there a way to simplify this?


wait_until(lambda : driver.find_element_by_xpath("//window[1]/tableview[1]/cell[2]/textfield[1]").is_displayed(), timeout=10)
do_until(lambda : driver.find_element_by_xpath("//window[1]/tableview[1]/cell[2/textfield[1]]").click())
driver.find_element_by_xpath("//window[1]/tableview[1]/cell[2]/textfield[1]").send_keys(get_username())

I was hoping for the first function to return an element that was found that way I could do this...

wait_until(lambda : driver.find_element_by_xpath("//window[1]/tableview[1]/cell[2]/textfield[1]").is_displayed(), timeout=10)
do_until(lambda : element.click())
element.send_keys(get_username())

...or something along those lines

David Lai

unread,
Mar 5, 2014, 8:00:31 PM3/5/14
to wtfra...@googlegroups.com
you can probably just do,

do_until(lambda : driver.find_element_by_xpath("//window[1]/tableview[1]/cell[2]/textfield[1]").click(), timeout=10)

Webdriver will raise a ElementNotVisibleException if it's not displayed, or a NoSuchElementException if the element is not present.

brandt...@gmail.com

unread,
Mar 5, 2014, 8:06:13 PM3/5/14
to wtfra...@googlegroups.com
I was able to get it a little more efficient:

element = lambda: driver.find_element_by_xpath("//window[1]/tableview[1]/cell[1]/textfield[1]")
wait_until(lambda : element().is_displayed(), timeout=10)
do_until(lambda : element().click())
element().send_keys(get_connect_user())

Reply all
Reply to author
Forward
0 new messages