I am developing framework for selenium automation and I have got stuck to get the dropdown option's value using dropdown. I have dropdown option but now I want the value of same dropdown. Is it possible to get it in selenium.
For example:
Here is the Html tag:
<select id="periodId" name="period" style="display: none;">
<option value="week1">1</option>
<option value="week2">2</option>
<option value="week3">3</option>
<option value="week4">4</option>
<option value="week5">5</option>
<option value="week16">6</option>
</select>
Now in the framework which I have developed, I will pass the dropdown option '5', now I want the value of dropdown option '5'. Is that possible to get value 'week5' for dropdown option '5' using selenium?
Try this and let me know.
Select period = new Select(driver.findElement(By.id("periodId")));
period.selectByVisibleText("5");
String value = period.getFirstSelectedOption().getAttribute("value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With