Selenium selectors on SVG TSPAN elements fail with certain versions of PhantomJS

蓝咒 提交于 2019-12-13 05:24:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!