有什么方法可以获取SmartGWT hightchart图中元素的定位符(sclocator或xpath等)吗?我需要自动执行对图形系列图例(显示在图形右侧的系列)的点击操作。
这些是我试图为该图的元素标识有效位置的东西:
任何帮助将不胜感激。
谢谢!
<g class="highcharts-legend" zIndex="7" transform="translate(-32,110)">
<g zIndex="1" clip-path="url(#highcharts-2)">
<g transform="translate(0,1)">
<g class="highcharts-legend-item" zIndex="1" transform="translate(8,3)">
<path fill="none" d="M 0 11 L 16 11" stroke-dasharray="none" stroke="#C00000" stroke-width="2"></path>
<path fill="#C00000" d="M 8 9 C 10.664 9 10.664 13 8 13 C 5.336 13 5.336 9 8 9 Z"></path>
<text x="21" y="15" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;color:#274b6d;fill:#274b6d;" text-anchor="start" zIndex="2">
<tspan x="21">Worst Inventory On Site</tspan>
</text>
</g>
<g class="highcharts-legend-item" zIndex="1" transform="translate(8,21)">
<path fill="none" d="M 0 11 L 16 11" stroke-dasharray="none" stroke="#3A5723" stroke-width="2"></path>
<path fill="#3A5723" d="M 8 9 C 10.664 9 10.664 13 8 13 C 5.336 13 5.336 9 8 9 Z"></path>
<text x="21" y="15" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;color:#274b6d;fill:#274b6d;" text-anchor="start" zIndex="2">
<tspan x="21">Total Ins</tspan>
</text>
</g>
<g class="highcharts-legend-item" zIndex="1" transform="translate(8,39)">
<path fill="none" d="M 0 11 L 16 11" stroke-dasharray="none" stroke="#CCC" stroke-width="2"></path>
<path fill="#CCC" d="M 8 9 C 10.664 9 10.664 13 8 13 C 5.336 13 5.336 9 8 9 Z"></path>
<text x="21" y="15" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;color:#CCC;fill:#CCC;" text-anchor="start" zIndex="2">
<tspan x="21">Total Outs</tspan>
</text>
</g>
<g class="highcharts-legend-item" zIndex="1" transform="translate(8,57)">
<path fill="none" d="M 0 11 L 16 11" stroke-dasharray="2,2" stroke="#CCC" stroke-width="2"></path>
<path fill="#CCC" d="M 8 9 C 10.664 9 10.664 13 8 13 C 5.336 13 5.336 9 8 9 Z"></path>
<text x="21" y="15" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;color:#CCC;fill:#CCC;" text-anchor="start" zIndex="2">
<tspan x="21">Inventory On Site</tspan>
</text>
</g>
<g class="highcharts-legend-item" zIndex="1" transform="translate(8,75)">
<path fill="none" d="M 0 11 L 16 11" stroke-dasharray="6,2" stroke="#CCC" stroke-width="2"></path>
<path fill="#CCC" d="M 8 9 C 10.664 9 10.664 13 8 13 C 5.336 13 5.336 9 8 9 Z"></path>
<text x="21" y="15" style="font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;font-size:12px;cursor:pointer;color:#CCC;fill:#CCC;" text-anchor="start" zIndex="2">
<tspan x="21">Inventory On Transit</tspan>
</text>
</g>
</g>
</g>
</g>
答案 0 :(得分:2)
感谢@ dangi13的帮助。但是我找到了使用不同的xpath结构的解决方案:
sharedData.appInstance.findElement(By.xpath("//[name()='g' and @class='highcharts-legend']//[name()='text']//*[name()='tspan' and text()='Worst Inventory on Site']")).click();
答案 1 :(得分:1)
您可以使用以下代码单击HighChart Elements:
/**
* @param graphName Use one of below values.
* Worst Inventory On Site
* Total Ins
* Total Outs
* Inventory On Site
* Inventory On Transit
*/
public void clickOnGraph(String graphName) {
WebElement graphElement = driver.findElement(By.xpath("//g[@class='highcharts-legend-item']//tspan[text()='" + graphName + "']"));
graphElement.click();
}
有关进一步的HighChart元素操作。您可以参考:
对于与HighCharts相关的Selenium操作非常有用。
如果常规点击不起作用,则可以尝试使用JavaScriptExecutor或Actions类进行点击。
请告诉我是否对您有帮助:)