Reputation: 1
I am not able to select option value from drop down list .select tag not containing any id or class or name.
<select>
<option title="Select" value="">Select</option>
<option title="Packages" value="PK" maxCount="1" cgCount="0">Packages</option>
</select>
Upvotes: 0
Views: 623
Reputation: 333
Just wrap your WebElement into Select Object as shown below
Select dropdown = new Select(driver.findElement(By.id("identifier"))); Once this is done you can select the required value in 3 ways. Consider an HTML file like this
<select id="designation">
<option value="MD">MD</option>
<option value="prog"> Programmer </option>
<option value="CEO"> CEO </option>
</select>
Below is the drop down :)
Now to identify dropdown do
1
Select dropdown = new Select(driver.findElement(By.id("designation")));
To select its option say 'Programmer' you can do ? 1
dropdown.selectByVisibleText("Programmer ");
or ? 1
dropdown.selectByIndex(1);
or ? 1
dropdown.selectByValue("prog");
or
dropdown.selectByVisibleText("Programmer");
Upvotes: 0
Reputation: 333
Use this, mine works :):
WebElement element = driver.findElement(By.xpath("//select"));
Select dropdown = new Select(element);
dropdown.selectByIndex(1);
Source: Sumit Mittal Blog
Upvotes: 2