Reputation: 361
I have a disabled drop down with Values auto populated as True or False. For the auto populated value, I can see a tag named "selected" when I do the inspect element.How can I verify whether the tag "Selected" is present for the drop down?
below is the HTML part
<select name="text" class="Product_Selected" disabled>
<Option value="Flag_True" selected>TRUE </option>
<Option value="Flag_False">False </option> ==$0
</select>
As you can see above, I have selected my previous input as TRUE, so next time im getting the drop down auto populated with TRUE and is DISABLED. Is there any way where I can see whether tag "selected" is present for that disabled drop down using JAVA code for Selenium Webdriver
OR Can I get the auto populated value of the Disabled Dropdown?
Upvotes: 0
Views: 127
Reputation: 25611
You don't have to do anything complicated... just treat it like any other SELECT
element. There is a special class in Selenium designed to make it easier to interact with SELECT
elements called... Select
. I just tested this code with true and false selected and it works just fine even though the element is disabled.
Select e = new Select(driver.findElement(By.cssSelector("select.Product_Selected")));
System.out.println(e.getFirstSelectedOption().getText());
You get your SELECT
element and send it to the Select
constructor. Then you can interact with the Select
element with all the new functionality. The example above just gets the selected option (first selected option in the case of a multi-select, but that doesn't apply here) and returns the text displayed, e.g. TRUE.
Upvotes: 1