Select Dropdown by Visible Text
Selenium provides the Select class (from org.openqa.selenium.support.ui.Select) to interact with HTML <select> elements.
selectByVisibleText() selects an option based on what the user sees.
HTML Structure:
<select id="singleSelect">
<option value="" disabled selected>Select Language</option>
<option value="java">Java</option>
<option value="python">Python</option>
<option value="javascript">JavaScript</option>
<option value="csharp">C#</option>
<option value="ruby">Ruby</option>
</select>
Task:
- Navigate to
https://testkru.com/Elements/Dropdowns
- Create a
Select object for the dropdown with ID singleSelect
- Select "Java" by visible text
- Print the selected option's text
Expected output:
Selected: Java