Reputation: 20202
I would like to select the first radio button on a web page via selenium (java) - I only have the value for the radio button and I know its the first button in the list of radio buttons. What would be the best approach for selecting this radio button - any helpful suggestions would be welcome.
I tried the following but it does not work (radio button has value of 1):
selenium.check("value=1");
Upvotes: 1
Views: 1194
Reputation: 387
Try to do like this :
List<WebElement> inputList=driver.findElements(By.tagName("input"));
for(int i=0;i<inputList.size();i++)
{
if (inputList.get(i).getAttribute("type").equalsIgnoreCase("radio"))
{
if(inputList.get(i).getAttribute("value").equals("1"))
{
inputList.get(i).click();
break;
}
}
}
Upvotes: 0
Reputation: 20202
I was able to use the following which worked:
selenium.click("//input[@value='1']");
Upvotes: 2