Skip to content
CodeKruPro

Choose a dropdown option by value

Automation taskEasyAsked in: Accenture, Capgemini, Infosys, SaaS Labs, TCS, Wipro

"What are the three ways to select an option?" By visible text, by value and by index. The value is the option's value attribute, which users never see, and it often stays the same when the label is translated.

Select Dropdown by Value with selectByValue()

Select Dropdown by Value

selectByValue() selects an option using its value attribute (which may differ from the visible text).

On the Dropdowns page, the singleSelect has options like:

  • <option value="python">Python</option>

Task:

  1. Navigate to https://testkru.com/Elements/Dropdowns
  2. Select the option with value python
  3. Print the displayed text of the selected option

Expected output:

Selected: Python