我正在尝试使用selenium模块在perl中自动化Web应用程序, 我在firefox版本27.0上使用selenium-server-standalone-2.39.0,
当我运行我的脚本时,我在这一行得到错误
$sel->click_ok("//g[contains(\@class,'highcharts-series-group')]//rect");
HTML的目的是:
<g class="highcharts-series-group" zIndex="3">
<g class="highcharts-series highcharts-tracker highcharts-tracker" visibility="visible" zIndex="0.1" transform="translate(27,20) scale(1 1)" style="cursor:pointer;" clip-path="url(#highcharts-347)">
<rect fill="rgb(86,161,220)" x="478" y="34" width="25" height="167" fill-opacity="1" rx="4" ry="4">
</g>
<g class="highcharts-markers" visibility="visible" zIndex="0.1" transform="translate(27,20) scale(1 1)">
</g>
我收到错误:错误:元素// g [包含(@ class,'highcharts-series-group')// rect] not found
提前致谢
示例:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<script type="text/javascript">
var rand="1390977827";
</script>
</head>
<body class="rdx_auto_cursor">
<div class="chart" data-highcharts-chart="1">
<div id="highcharts-2" class="highcharts-container" style="position: relative; overflow: hidden; width: 1029px; height: 250px; text-align: left; line-height: normal; z-index: 0; font-family: "Lucida Grande","Lucida Sans Unicode",Verdana,Arial,Helvetica,sans-serif; font-size: 12px; left: 0.199997px; top: 0.199997px;">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="1029" height="250">
<desc>Created with Highcharts 3.0.2</desc>
<defs>
<clipPath id="highcharts-3">
<rect fill="none" x="1" y="1" width="980" height="198">
</rect>
</clipPath>
</defs>
<g class="highcharts-series-group" zIndex="3">
<g class="highcharts-series highcharts-tracker highcharts-tracker highcharts-tracker" visibility="visible" zIndex="0.1" transform="translate(27,20) scale(1 1)" style="cursor:pointer;" clip-path="url(#highcharts-3)">
<rect fill="rgb(86,161,220)" x="478" y="100" width="25" height="100" fill-opacity="1" rx="4" ry="4">
</rect>
</g>
<g class="highcharts-markers" visibility="visible" zIndex="0.1" transform="translate(27,20) scale(1 1)">
</g>
</g>
</svg>
</div>
</body>
</html>
答案 0 :(得分:0)
您是否正试图点击SVG元素?
请参阅http://www.qaautomation.net/?p=388“XPath命名空间”
试试这个表达式:
//*[local-name()='g']
[contains(@*[local-name()='class'],'highcharts-series-group')]
//*[local-name()='rect']
也许有办法注册SVG名称空间,然后使用
//svg:g[contains(@svg:class,'highcharts-series-group')]//svg:rect
更详细的一点是:
//*[local-name()='g' and namespace-uri()='http://www.w3.org/2000/svg']
[contains(
@*[local-name()='class' and namespace-uri()='http://www.w3.org/2000/svg'],
'highcharts-series-group')]
//*[local-name()='rect']