Webdriver error

I tried one of the programs from your site on my own and I get the below error. This program is present in the Multi select boxes and drop downs section of your time. The error is :

Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at DDs_MultiSelect.main(DDs_MultiSelect.java:37)

for the following program:

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;
import java.util.concurrent.TimeUnit;

public class DDs_MultiSelect {

public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver ();

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

WebElement e1 = driver.findElement(By.id(“continents”));

Select oSelect = new Select(e1);

oSelect.selectByVisibleText(“Australia”);

Thread.sleep(2000);

oSelect.selectByIndex(2);

Thread.sleep(2000);

List <WebElement> e2 = oSelect.getOptions();

int a = e2.size();

for (int b=0; b < a; b++) {

String s = oSelect.getOptions().get(a).getText();

System.out.println(s);

if(s.equals(“Africa”))

oSelect.selectByIndex(a);
break;

}

}

}

Could you please advise as to what could be the problem ?

Mohit

Default Asked on September 29, 2015 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    oSelect.selectByIndex(a);

    should be
    oSelect.selectByIndex(b);

    a will give your out of bound error

    Virender

    Professor Answered on September 29, 2015.
    Add Comment
  • Your Answer

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