diff --git a/common/test/acceptance/tests/helpers.py b/common/test/acceptance/tests/helpers.py index d2cf2f5488..922a0e9993 100644 --- a/common/test/acceptance/tests/helpers.py +++ b/common/test/acceptance/tests/helpers.py @@ -21,6 +21,7 @@ from pymongo import MongoClient, ASCENDING from openedx.core.lib.tests.assertions.events import assert_event_matches, is_matching_event, EventMatchTolerates from xmodule.partitions.partitions import UserPartition from xmodule.partitions.tests.test_partitions import MockUserPartitionScheme +from selenium.common.exceptions import StaleElementReferenceException from selenium.webdriver.support.select import Select from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC @@ -201,18 +202,36 @@ def enable_css_animations(page): def select_option_by_text(select_browser_query, option_text): """ Chooses an option within a select by text (helper method for Select's select_by_visible_text method). + + Wrap this in a Promise to prevent a StaleElementReferenceException + from being raised while the DOM is still being rewritten """ - select = Select(select_browser_query.first.results[0]) - select.select_by_visible_text(option_text) + def select_option(query, value): + try: + select = Select(query.first.results[0]) + select.select_by_visible_text(value) + return True + except StaleElementReferenceException: + return False + EmptyPromise(lambda: select_option(select_browser_query, option_text), 'Selected option {}'.format(option_text)).fulfill() def get_selected_option_text(select_browser_query): """ Returns the text value for the first selected option within a select. - """ - select = Select(select_browser_query.first.results[0]) - return select.first_selected_option.text + Wrap this in a Promise to prevent a StaleElementReferenceException + from being raised while the DOM is still being rewritten + """ + def get_option(query): + try: + select = Select(select_browser_query.first.results[0]) + return (True, select.first_selected_option.text) + except StaleElementReferenceException: + return (False, None) + + text = Promise(lambda: get_option(select_browser_query), 'Retrieved selected option text').fulfill() + return text def get_options(select_browser_query): """