i am new to Java and Selenium and try to learn The Problem is, that i do not know how to extract names from a Dropdown Menu using the Select class
I have created a Variable Array String with the Expected Results
I have created a new object for Select Class and pass the xpath
I have created a List to store all the options from the Dropdown
Then i have a For Loop to iterate in all items in the loop and take the names
But i have no method to extract the name.
The question is how we can do that? Using the Select.
Thanks in advance for your help
Practice Website is this one: http://qaclickacademy.com/practice.php
HTML CODE:
<select id="dropdown-class-example" name="dropdown-class-example" wtx-context="4CBF2E98-EC2A-4384-8B92-4FB100C9F504" style="" xpath="1">
<option value="">Select</option>
<option value="option1" style="">Option1</option>
<option value="option2">Option2</option>
<option value="option3">Option3</option>
</select>
MY CODE:
String expectedDropDownItems [] = {"Select","option1","option2","option3"};
Select dropDownSelect = new Select(driver.findElement(By.id("dropdown-class-example")));
List<WebElement> dropDownActualValues = dropDownSelect.getOptions();
int counter = dropDownActualValues.size();
for (int i=0; i < counter; i++){
}
Expected and Actual something like this :
Selection 1 is : Select
Selection 2 is : option1
Selection 3 is : option2
Selection 4 is : option3