From fa376de26067e5db2d6673dc4a2f6e83b5420321 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sun, 6 Nov 2022 18:21:47 +0100 Subject: [PATCH] Fix select2 value selection in selenium --- lib/galaxy/selenium/navigates_galaxy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/selenium/navigates_galaxy.py b/lib/galaxy/selenium/navigates_galaxy.py index c7ad6608d08..91e44323734 100644 --- a/lib/galaxy/selenium/navigates_galaxy.py +++ b/lib/galaxy/selenium/navigates_galaxy.py @@ -1934,7 +1934,15 @@ class NavigatesGalaxy(HasDriver): # Wait for select2 options to load and then click to add this one. self.send_enter(text_element) else: - select_elem = drop_elem.find_elements(By.CSS_SELECTOR, ".select2-result-label")[0] + candidate_elements = drop_elem.find_elements(By.CSS_SELECTOR, ".select2-result-label") + # try to find exact match + for elem in candidate_elements: + if elem.text == value: + select_elem = elem + break + else: + # Pick first match. We're replacing select2 anyway ... + select_elem = elem action_chains = self.action_chains() action_chains.move_to_element(select_elem).click().perform() self.wait_for_selector_absent_or_hidden("#select2-drop")