Attempt work around for race-y sort of condition in Selenium sizzle checkers.

I believe this rare condition explains this failing test here - https://jenkins.galaxyproject.org/view/All/job/selenium/54/testReport/junit/selenium_tests.test_stock_tours/TestStockToursTestCase/test_core_history/. This test has never failed for me locally and this is the only time I've seen it fail on Jenkins as well.
This commit is contained in:
John Chilton
2017-01-19 11:47:10 -05:00
parent b4475ba9df
commit bf84aca059
+29 -2
View File
@@ -15,7 +15,21 @@ def sizzle_selector_clickable(selector):
if not elements:
return False
element = elements[0]
if element.is_displayed() and element.is_enabled():
try:
clickable = element.is_displayed() and element.is_enabled()
except Exception as e:
# Handle the case where the element is detached between when it is
# discovered and when it is checked - it is likely changing quickly
# and the next pass will be the final state. If not, this should be
# wrapped in a wait anyway - so no problems there. For other
# non-custom selectors I believe this all happens on the Selenium
# server and so there is likely no need to handle this case - they
# are effectively atomic.
if _exception_indicates_stale_element(e):
return None
raise
if clickable:
return element
else:
return None
@@ -29,7 +43,16 @@ def sizzle_presence_of_selector(selector):
if not elements:
return False
element = elements[0]
if element.is_displayed():
try:
displayed = element.is_displayed()
except Exception as e:
# See note above insizzle_selector_clickable about this exception.
if _exception_indicates_stale_element(e):
return None
raise
if displayed:
return element
else:
return None
@@ -37,6 +60,10 @@ def sizzle_presence_of_selector(selector):
return ec
def _exception_indicates_stale_element(exception):
return "stale" in str(exception)
def find_element_by_sizzle(driver, sizzle_selector):
"""
Finds an element by sizzle selector.