Skipping through elements on SVG bar graph in Selenium webdriver

I’ve build a method in java for selenium, whereby I want to click on an SVG bar graph and click on the first 3 bars (screenshot below)

Skipping through elements on SVG bar graph in Selenium webdriver

I’ve done this by implementing the below code:

public static void barChartSelector(InternetExplorerDriver driver)



WebElement parent = driver.findElement(By.className("highcharts-series-group"));


List<WebElement> children = parent.findElements(By.tagName("rect"));







However, what I’m finding is that I sometimes get this error: “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 2, Size: 0 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at genericControls.graphSelectors.relationalBarChartSelector( at Reports.collections.breachReportCompletedFunctions( at Reports.programMain.main(”

It looks like when I run the ‘get’ command, the graph isn’t always indexed the same from page to page, so on some pages it will work and some pages it will fail. My thinking is that I need to implement a ‘for’ loop so that I can still run the ‘children.get(X).click();’ event, but instead of falling over if the code cannot find the first event, it loops through until it finds the ‘get’ command that returns a result.

Please could someone advise me how I might convert my code above into a ‘for’ loop so that it can look for any of the ‘children’ elements that might meet the criteria? This will help me with my understanding of how to implement this in future.

Train Asked on December 16, 2014 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

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