diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index 75bc8bb..e400ca9 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -190,6 +190,19 @@ def css_click_at(css_selector, index=0, x_coord=10, y_coord=10, timeout=5): @world.absorb +def select_option(name, value, index=0, wait_time=30): + ''' + A method to select an option + This method will return True if the selection worked. + ''' + select_css = "select[name='{}']".format(name) + option_css = "option[value='{}']".format(value) + + css_selector = "{} {}".format(select_css, option_css) + return css_click(css_selector=css_selector, index=index, wait_time=wait_time) + + +@world.absorb def id_click(elem_id): """ Perform a click on an element as specified by its id diff --git a/lms/djangoapps/courseware/features/problems_setup.py b/lms/djangoapps/courseware/features/problems_setup.py index 3b1b983..a705a84 100644 --- a/lms/djangoapps/courseware/features/problems_setup.py +++ b/lms/djangoapps/courseware/features/problems_setup.py @@ -166,9 +166,7 @@ def answer_problem(problem_type, correctness): if problem_type == "drop down": select_name = "input_i4x-edx-model_course-problem-drop_down_2_1" option_text = 'Option 2' if correctness == 'correct' else 'Option 3' - # First wait for the element to be there on the page - world.wait_for_visible("select#{}".format(select_name)) - world.browser.select(select_name, option_text) + world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': @@ -244,7 +242,7 @@ def problem_has_answer(problem_type, answer_class): if answer_class == 'blank': assert world.is_css_not_present('option[selected="true"]') else: - actual = world.browser.find_by_css('option[selected="true"]').value + actual = world.css_value('option[selected="true"]') expected = 'Option 2' if answer_class == 'correct' else 'Option 3' assert actual == expected @@ -305,10 +303,6 @@ def problem_has_answer(problem_type, answer_class): pass -############################## -# HELPER METHODS -############################## - def add_problem_to_course(course, problem_type, extraMeta=None): ''' Add a problem to the course we have created using factories.