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)

{

genericControls.waitCommands.fluentWaitOnBarChartSelector(driver);

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

genericControls.waitCommands.fluentWaitOnBarChartSelector(driver);

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

genericControls.waitCommands.fluentWaitOnBarChartSelector(driver);

children.get(0).click();

children.get(1).click();

children.get(2).click();

genericControls.waitCommands.fluentWaitOnRelationalBarGraphDisplay(driver);

}

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(graphSelectors.java:34) at Reports.collections.breachReportCompletedFunctions(collections.java:30) at Reports.programMain.main(programMain.java:37)”

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.

tilston1001 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.