Search code examples
highchartsselenium-webdriverphantomjsselenium-chromedrivergeb

Unable to assert axis label text in highcharts using Geb


I am writing a geb test that asserts the axis labels in a highcharts graph.

The test I wrote works when run with the selenium chrome driver. When I run with phantomjs it fails.

//Selector in GEB

$(id:"graph-id").find("g.highcharts-legend-item").find("tspan").text()

This returns as expected in Chrome. It returns empty in phantomjs.

We have to use phantomjs for our CI builds.


Solution

  • If for whatever reason geb isn't supporting your phantomjs driver properly, you can always execute a javascript selector directly through the browser:

    def webElements = browser.driver.executeScript("""return document.querySelectorAll("#graph-id g.highcharts-legend-item tspan"); """)
    def gebNavigators = webElements.collect{ new NonEmptyNavigator(browser, it) }
    

    Which will give you a list of geb navigators which point to the selected elements.