java - Skipping through elements on SVG bar graph in Selenium webdriver -
i've build method in java selenium, whereby want click on svg bar graph , click on first 3 bars (screenshot below) i've done implementing 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, i'm finding error:
"exception in thread "main" java.lang.indexoutofboundsexception: index: 2, size: 0 @ java.util.arraylist.rangecheck(unknown source) @ java.util.arraylist.get(unknown source) @ genericcontrols.graphselectors.relationalbarchartselector(graphselectors.java:34) @ reports.collections.breachreportcompletedfunctions(collections.java:30) @ reports.programmain.main(programmain.java:37)"
it looks when run 'get' command, graph isn't indexed same page page, on pages work , pages fail. thinking need implement 'for' loop can still run 'children.get(x).click();' event, instead of falling on if code cannot find first event, loops through until finds 'get' command returns result.
please advise me how might convert code above 'for' loop can of 'children' elements might meet criteria? me understanding of how implement in future.
seems me problem here: list children = parent.findelements(by.tagname("rect"));
the indexoutofboundsexception
thrown because children
doesn't contain 3 webelements.
try replacing this:
list<webelement> children = parent.findelements(by.tagname("rect")); genericcontrols.waitcommands.fluentwaitonbarchartselector(driver); (webelement child : children) { if (children.indexof(child) > 2) break; child.click(); }
nb, i'm assuming there may more 3 "rect" webelements, , you're interested in clicking first 3. remove if statement if want click rect elements.
Comments
Post a Comment