Commit 93edfb0b by Will Daly

Merge pull request #1268 from edx/will/fix-problem-acceptance

Guard against StaleElementException in css_click
parents c6b6a278 936b933a
...@@ -336,8 +336,10 @@ def css_click(css_selector, index=0, wait_time=30): ...@@ -336,8 +336,10 @@ def css_click(css_selector, index=0, wait_time=30):
This method will return True if the click worked. This method will return True if the click worked.
""" """
wait_for_clickable(css_selector, timeout=wait_time) wait_for_clickable(css_selector, timeout=wait_time)
assert_true(world.css_find(css_selector)[index].visible, assert_true(
msg="Element {}[{}] is present but not visible".format(css_selector, index)) world.css_visible(css_selector, index=index),
msg="Element {}[{}] is present but not visible".format(css_selector, index)
)
# Sometimes you can't click in the center of the element, as # Sometimes you can't click in the center of the element, as
# another element might be on top of it. In this case, try # another element might be on top of it. In this case, try
...@@ -368,9 +370,10 @@ def css_click_at(css_selector, index=0, x_coord=10, y_coord=10, timeout=5): ...@@ -368,9 +370,10 @@ def css_click_at(css_selector, index=0, x_coord=10, y_coord=10, timeout=5):
rather than in the center of the element rather than in the center of the element
''' '''
wait_for_clickable(css_selector, timeout=timeout) wait_for_clickable(css_selector, timeout=timeout)
element = css_find(css_selector)[index] assert_true(
assert_true(element.visible, world.css_visible(css_selector, index=index),
msg="Element {}[{}] is present but not visible".format(css_selector, index)) msg="Element {}[{}] is present but not visible".format(css_selector, index)
)
element.action_chains.move_to_element_with_offset(element._element, x_coord, y_coord) element.action_chains.move_to_element_with_offset(element._element, x_coord, y_coord)
element.action_chains.click() element.action_chains.click()
...@@ -512,7 +515,6 @@ def retry_on_exception(func, max_attempts=5, ignored_exceptions=StaleElementRefe ...@@ -512,7 +515,6 @@ def retry_on_exception(func, max_attempts=5, ignored_exceptions=StaleElementRefe
while attempt < max_attempts: while attempt < max_attempts:
try: try:
return func() return func()
break
except ignored_exceptions: except ignored_exceptions:
world.wait(1) world.wait(1)
attempt += 1 attempt += 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment