WebDriver Tutorial – Check Box and Radio Button commands

I’m just going through the  Selenium tutorial and  having problems with the isSelected code. The List data type is coming up as a warning stating that it is
a raw type which needs to be parameterized which in turn means that the
isSelected & click methods are throwing up errors. If I change the List
data type to List<WebElement> the errors disappear but the boolean shows a warning and when run it throws up the following:
Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at testFramework.PracticeRadioOps.main(PracticeRadioOps.java:26)

Is there something I’m missing here?

Here’s the code I’m attempting to run:

package testFramework;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PracticeRadioOps {

public static WebDriver driver;
public static void main(String[] args) {

driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get(“http://www.toolsqa.com/automation-practice-form/”);

List<WebElement> oRadioButton = driver.findElements(By.name(“toolsqa”));

boolean bValue = false;

bValue = oRadioButton.get(0).isSelected();

if(bValue = true){

oRadioButton.get(1).click();

}else{

oRadioButton.get(0).click();
}

}

}

I’m currently running selenium 2.45.0 in Eclipse IDE Luna v4.4.0.

Any help would be greatly appreciated.

Thanks

Add Comment
  • 1 Answer(s)

    I think you did not debug  your code before posting this question. driver.findElements(By.name(“toolsqa”)) should be driver.findElements(By.name(“tool”));

    Virender

    Professor Answered on June 29, 2015.

    How embarrassing (lesson learnt). Thank you Virender. Of course, that now works fine.

    on June 30, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.