java.lang.IndexOutOfBoundsException Index 4 Size 3 on retieving the data2

public class Booking

{

WebDriver driver = new ChromeDriver();

public void Homepage() throws IOException, InterruptedException

{

driver.get(“http://www-stg.jetblue.com”); driver.manage().window().maximize();

WebElement radio = driver.findElement(By.xpath(“//div[@id=’login-search-wrap’]/div[3]/div/div[3]/form/div[3]/div/ul/li[2]/label/span[2]”)); radio.click();

ArrayList<String> data = Excel1(0);

ArrayList<String> data1 = Excel1(1);

driver.findElement(By.id(“jbBookerDepart”)).clear(); driver.findElement(By.id(“jbBookerDepart”)).sendKeys(data.get(0)); driver.findElement(By.id(“jbBookerArrive”)).sendKeys(data1.get(1)); driver.findElement(By.id(“jbBookerCalendarDepart”)).sendKeys(“8-12-2017”); //driver.findElement(By.id(“jbBookerCalendarReturn”)).sendKeys(“8-25-2017”);

driver.findElement(By.xpath(“//div[@id=’login-search-wrap’]/div[3]/div/div[3]/form/input[5]”)).click();

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

WebElement radiobutton1 = driver.findElement(By.id(“itineraryPriceCell_0_5”)); radiobutton1.click();

JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“scroll(0, 3000)”); WebElement menu = driver.findElement(By.xpath(“//div[@class=’pageButtonArea’]/table/tbody/tr/td/a”));

Actions build = new Actions(driver);

build.moveToElement(menu).build().perform();

WebElement m2m= driver.findElement(By.xpath(“//div[@class=’pageButtonArea’]/table/tbody/tr/td”));//the previous non visible element m2m.click();

driver.findElement(By.xpath(“//div[@id=’popupBaggageTermsBundleDialog’]/div[4]/table/tbody/tr/td[2]/a/span/span”)).click();

this.TravelInfo();

} public void TravelInfo() throws IOException

{ new Select(driver.findElement(By.id(“travellersInfo[0].title”))).selectByValue(“MR”); ArrayList<String> data2 = Excel1(4); driver.findElement(By.id(“travellersInfo[0].firstName”)).sendKeys(data2.get(4));

}

public ArrayList<String> Excel1(int col) throws IOException

{

FileInputStream IS = new FileInputStream(“C:\\Users\\shjain\\workspace\\BookingFlow\\DataTest.xlsx”); XSSFWorkbook WB = new XSSFWorkbook(IS);

XSSFSheet Sheet = WB.getSheet(“Sheet1”);

String data = Sheet.getRow(1).getCell(0).getStringCellValue();

String data1 = Sheet.getRow(1).getCell(1).getStringCellValue(); String data2 = Sheet.getRow(1).getCell(4).getStringCellValue();

// String data3 = Sheet.getRow(1).getCell(5).getStringCellValue();

ArrayList<String> List = new ArrayList<String>();

List.add(data);

List.add(data1);

List.add(data2);

return List;

}

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

{

System.setProperty(“webdriver.chrome.driver”, “C:\\chromedriver_win32\\chromedriver.exe”);

Booking book = new Booking();

book.Homepage();

}}

 

Error 

Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 4, Size: 3

at java.util.ArrayList.rangeCheck(Unknown Source)

at java.util.ArrayList.get(Unknown Source)

at TrueBlueBooking.Booking.TravelInfo(Booking.java:78)

at TrueBlueBooking.Booking.Homepage(Booking.java:66)

at TrueBlueBooking.Booking.main(Booking.java:109)

Default Asked on February 28, 2017 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

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