问题
I am using Geb and Selenium, and noticed that tests that reference certain SVG elements fail on certain PhantomJS versions. This test running against the Highcharts demo site passes if I'm using PhantomJS 1.9.1, but fails on 1.9.7 - the SVG tspan
element is successfully located (size() > 0
passes) but text()
returns empty string.
I have been able to isolate that the problem is not Geb specifically - I get the same problem when I interact with the PhantomJSDriver
directly.
So I don't where to go next to troubleshoot this: is it a problem in the PhantomJS remote driver, or in PhantomJS itself? How would I troubleshoot where the problem is?
import geb.spock.GebReportingSpec;
class TspanSpec extends GebReportingSpec {
def "tspan elements found but can't get text"() {
when:
go "http://www.highcharts.com/demo/bar-stacked"
then:
waitFor { $("g.highcharts-axis").find("tspan").size() > 0 }
$("g.highcharts-axis").find("tspan").text() == "Total fruit consumption"
}
}
回答1:
Found a workaround: retrieve text with jQuery object instead of WebElement.
$("g.highcharts-axis").find("tspan").jquery.text() == "Total fruit consumption"
来源:https://stackoverflow.com/questions/25693949/selenium-selectors-on-svg-tspan-elements-fail-with-certain-versions-of-phantomjs