From 5b04fb7ae3c90beee80988c13ec1358ba12e2285 Mon Sep 17 00:00:00 2001 From: byron Date: Fri, 9 Aug 2019 14:43:53 -0400 Subject: [PATCH] add api for dropdown --- dash/testing/browser.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dash/testing/browser.py b/dash/testing/browser.py index 5f4ae54eac..85f3fd678c 100644 --- a/dash/testing/browser.py +++ b/dash/testing/browser.py @@ -232,6 +232,34 @@ def wait_for_page(self, url=None, timeout=10): ) ) + def select_dcc_dropdown(self, selector, value=None, index=None): + dropdown = self.driver.find_element_by_css_selector(selector) + dropdown.click() + + menu = dropdown.find_element_by_css_selector("div.Select-menu-outer") + logger.debug( + "the available options are %s", "|".join(menu.text.split("\n")) + ) + + options = menu.find_elements_by_css_selector( + "div.VirtualizedSelectOption" + ) + if options: + if isinstance(index, int): + options[index].click() + return + + for option in options: + if option.text == value: + option.click() + return + + logger.error( + "cannot find matching option using value=%s or index=%s", + value, + index, + ) + def toggle_window(self): """switch between the current working window and the new opened one""" idx = (self._window_idx + 1) % 2