isSelected() always returning false even though radio button is in selected state.
below is my HTML when radio button not selected
<input type="radio" class="chkbox" name="time1" value="3">
And below is my HTML when radio button selected
<input type="radio" class="chkbox" name="time1" value="3" checked> == $0
isSelected returning false for both the cases
driver.findElement(By.name("time1")).isSelected()
Also I had tried with getAttribute("checked") and it is returning null
driver.findElement(By.name("time1")).getAttribute("checked")
Can someone help me to get radio button selected state!!!
I am using following workaround to get radio button selected state for my HTML
public boolean isRadioButtonSelected() {
if(driver.findElement(By.xpath("//*[@name='time1' and @value='3']")).isDisplayed()) {
return driver.findElement(By.xpath("//*[@name='time1' and @value='3' and @checked]")).isDisplayed();
}
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.