Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
4.9k views
by The go-to Tester (391 points)
at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at pageObjects.LatestArticles.clickArticleLink(LatestArticles.java:133)
    at testCases.VerifyLatestArticles.verifyLoadLatestArticles(VerifyLatestArticles.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

2 Answers

0 like 0 dislike
by The go-to Tester (181 points)
It looks like you are using Array and trying to access certain element.

 

This error occures when array or collection size is lessear then expected.

E.g. when you say String[] values = otherElement.getValues();

You are expecting values size to be 10 and so you try to access values[9] but actual values size is < 10. So no way you have values[9] in place.  In that case you will face above error.

Best way to resolve that is by placing if condition before accessing the value.

 

E.g.

String singleValue;

String[] values = otherElement.getValues();

if(values.length >= 10)

singleValue = values[9];

 

Hope that helps.
0 like 0 dislike
by

If ArrayList Size = 1 And Index = 1

java.util.ArrayList.get(Index)==> java.lang.IndexOutOfBoundsException

by The go-to Tester (181 points)
Array starts from 0. So to get the first array I should be using java.util.ArrayList.get(Index - 1).

Hope that helps.
by
Good:Array starts from 0


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...