why Radio Button size() showing 0 in Selenium?

Issue

WebDriver driver = new FirefoxDriver();
driver.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio");
List<WebElement> radio_buttons = driver.findElements(By.name("gender"));
System.out.println(radio_buttons.size());

Solution

Those elements are inside <iframe id="iframeResult" frameborder="0">. You need to switch to iframe first:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio");

WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("iframeResult")));

List<WebElement> radio_buttons = driver.findElements(By.name("gender"));
System.out.println(radio_buttons.size());

Answered By – sfgblackwarkrts

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published