DEV Community

Cover image for Easiest Way to Handle Drop Down Menus in Python Using Selenium ?
Ali
Ali

Posted on

1

Easiest Way to Handle Drop Down Menus in Python Using Selenium ?

Introduction

Selenium has a neat way to handle drown down menus by using the Select function.

For this example, we will testing it out on:
https://app.endtest.io/guides/docs/how-to-test-dropdowns/

Drop down test

Importing the Select class

First let’s import the Select function.

from selenium.webdriver.support.select import Select

Finding the Drop Down Element

Now let's call the drop down by using its ID, which is pets and name its instance drop_down.

drop_down = driver.find_element_by_id('pets')

Selecting the drop down

Now we've got the drop down selected and will name its instance drop.

drop = Select(drop_down)

There are multiple ways we can select values in a drop down menu, either by index, value or visible text.

Selecting by Index

drop.select_by_index(2)

Selecting by Value

drop.select_by_value('cat')

Selecting by Visible Text

drop.select_by_visible_text("Dog")

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay