SVG TSPAN元素上的硒选择器在某些版本的PhantomJS上失败 [英] Selenium selectors on SVG TSPAN elements fail with certain versions of PhantomJS

查看:88
本文介绍了SVG TSPAN元素上的硒选择器在某些版本的PhantomJS上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Geb和Selenium,并注意到引用某些SVG元素的测试在某些PhantomJS版本上失败.如果我使用PhantomJS 1.9.1,则针对Highcharts演示站点运行的此测试通过,但在1.9.7上失败-SVG tspan元素已成功定位(size() > 0通过),但text()返回空字符串. /p>

我已经能够隔离出问题不是专门针对Geb的问题-当我直接与PhantomJSDriver进行交互时,也会遇到相同的问题.

因此,我没有下一步要解决的问题:PhantomJS远程驱动程序还是PhantomJS本身存在问题吗?我该如何解决问题所在?

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"
    }
}

解决方案

找到了一种解决方法:使用jQuery对象而不是WebElement检索文本.

$("g.highcharts-axis").find("tspan").jquery.text() == "Total fruit consumption"

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"
    }
}

解决方案

Found a workaround: retrieve text with jQuery object instead of WebElement.

$("g.highcharts-axis").find("tspan").jquery.text() == "Total fruit consumption"

这篇关于SVG TSPAN元素上的硒选择器在某些版本的PhantomJS上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆