Selecting dropdown in a Selenium test environment

Hey, I am creating a Webapp created with Dash. Until now, I have just used selenium as the app is hosted online and I was able to use the basic features. However, when it comes to selecting a dropdown, selenium cant help anymore. In other threats etc. I found information about the dropdown integration tests on dash/plotly github, but this seems like a completely different way so that i would need to change my whole other tests and knowledge about selenium as well. Is there a way to integrate the dropdown selection easier into a selenium code?

Thanks for your help


I am a newbie on this topic, but I have faced the same issue recently when I wanted to add some tests in a Streamlit app with a dropdown selection. Dash has similar issues because they don’t use a select tag, so the “Select” class in selenium can’t interact with it. Besides, the options in dcc.Dropdown are virtualized and its block appears only when the dropdown is opened.

What worked for me was to manually open the dropdown, search for the div with the options, picking the one I wanted to select by text and clicking on it.

You can use for inspiration how the search function is tested in Dash:

The difference here is that they are just checking how many options are returned, but they don’t click in any of them to test how the selection works (maybe they do in another test, not sure). Plus, you are not obliged to use the dash_dcc fixture, as you can simply use the selenium driver, however the Dash fixtures are convenient to start the app in the test function… For “vanilla” selenium in Streamlit I had to start the app in a subprocess on TestCase.setUp, which is a bit more of a hassle.

I hope this comment can provide you some help in trying to figure this out. :slightly_smiling_face: