-4

I want to store it in a Arraylist in the following order :

  • topcompany.get(i).getText(),
  • avg_exp.get(i).getText(),
  • avg_sal.get(i).getText(),
  • inlakhs.get(j).getText(),
  • circle_text.get(i).getText(),
  • inlakhs.get(j+1).getText()

My code:

 List<WebElement> topcompany = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='a']//*[name()='text']//*[name()='tspan' and @dy='4']"));
 List<WebElement> avg_exp = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @x='245']//*[name()='tspan' and @dy='4']"));
 List<WebElement> avg_sal = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @x='295']//*[name()='tspan' and @dy='4']"));
 List<WebElement> inlakhs = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @fill='#000000']//*[name()='tspan' and @dy='3.5']"));
 List<WebElement> circle_text = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='a']//*[name()='text' and @fill='#ffffff']//*[name()='tspan' and @dy='3.5']")); 

 for(int i=0;i<topcompany.size();i++) {
     for(int j=4;j<inlakhs.size();j++) {
         //main_list.add(new String[] {topcompany.get(i).getText(),avg_exp.get(i).getText(),avg_sal.get(i).getText(),inlakhs.get(j).getText(),circle_text.get(i).getText(),inlakhs.get(j+1).getText()});
     }
 }
Vincent Passau
  • 814
  • 8
  • 22
etishree
  • 17
  • 3

2 Answers2

0

It is very hard to understand what you are trying to achieve.

But here is a starting point : If we request for an index that is either negative, or greater than or equal to the size of the array, an ArrayIndexOutOfBoundsException is thrown.

In your case, inlakhs.get(j+1).getText() is going to throw an error when j reaches inlakhs.size() - 1 because then j will be equals to the size of the list.

You must fix this first and you will see this error disappears

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
rilent
  • 659
  • 1
  • 6
  • 22
0

Your issues is clearly caused by accessing a list with an index out of range. Run the following code to debug and find out what list in particular is causing the exception:

    List<WebElement> topcompany = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='a']//*[name()='text']//*[name()='tspan' and @dy='4']"));
    List<WebElement> avg_exp = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @x='245']//*[name()='tspan' and @dy='4']"));
    List<WebElement> avg_sal = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @x='295']//*[name()='tspan' and @dy='4']"));
    List<WebElement> inlakhs = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='text' and @fill='#000000']//*[name()='tspan' and @dy='3.5']"));
    List<WebElement> circle_text = driver.findElements(By.xpath("(//*[name()='svg'])[2]//*[name()='a']//*[name()='text' and @fill='#ffffff']//*[name()='tspan' and @dy='3.5']"));


    java.util.List<java.util.List<WebElement>> elements = new java.util.ArrayList<java.util.List<WebElement>>();
    for(int i=0;i<topcompany.size();i++)
    {
        for(int j=4;j<inlakhs.size();j++)
        {
            for (java.util.List<WebElement> list : elements) {
                try {
                    WebElement element = list.get(i);
                }
                catch (ArrayIndexOutOfBoundsException e) {
                    System.out.printf("%s caused an exception at index %d", element.toString(), i);
                }
            }
        }
    }
Matthew
  • 1,905
  • 3
  • 19
  • 26