s.selectByIndex(i); //<---------====================Local variable s may not be resolved
Have put some comments in code :
-------------------------------------
package p111;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Radiobuttons {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver w=new FirefoxDriver();
w.get("http://www.echoecho.com/htmlforms10.htm");
//----L is reference of List class---------------------
List<WebElement> L=new ArrayList <WebElement>();
L=w.findElements(By.name("group1"));
System.out.println(L.size());
//-----------------------
Select s;//Selcet class reference creation
//------------------------
for(int i=0;i<L.size();i++){
System.out.println("---"+L.get(i).getAttribute("value"));
try{
s=new Select(L.get(i));
}
catch(Exception e)
{
}
//=======================================================================================
finally{
s.selectByIndex(i); //<----This line i get error:-Local variable s may not be resolved
}
//=======================================================================================
System.out.println(L.get(i).getAttribute("checked"));
}
}
}
you have to initiate[color=#FF0000:3n8moqob] s=new Select(L.get(i));[/color:3n8moqob] outside try catch block.
I get org.openqa.selenium.support.ui.UnexpectedTagNameException for the line highlighted below:
package p111;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class Radiobuttons {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver w=new FirefoxDriver();
w.get("http://www.echoecho.com/htmlforms10.htm");
//----L is reference of List class---------------------
List<WebElement> L=new ArrayList <WebElement>();
L=w.findElements(By.name("group1"));
System.out.println(L.size());
int i=0;
//======================================================================================
Select s=new Select(L.get(i));////<---------org.openqa.selenium.support.ui.UnexpectedTagNameException
//===================================================================================
for(i=0;i<L.size();i++){
System.out.println("---"+L.get(i).getAttribute("value"));
//s=new Select(L.get(i));
try{
}
catch(Exception e)
{
}finally{
s.selectByIndex(i);
}
System.out.println(L.get(i).getAttribute("checked"));
}
}
}
[quote:3lxvjj3t]
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "input"
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'[/quote:3lxvjj3t]
your program will not work because Select is for drop down menus and you're using it on radio buttons.