首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用selenium单击svg路径元素

无法使用selenium单击svg路径元素
EN

Stack Overflow用户
提问于 2016-09-22 19:40:42
回答 1查看 1.6K关注 0票数 0

我正致力于图表数据的自动化,下面是数据的表示方式。

代码语言:javascript
复制
<g style="cursor:pointer;" clip-path="url(#highcharts-2)" transform="translate(62,10) scale(1 1)" class="highcharts-markers highcharts-series-0 highcharts-tracker">
<path d="M 811 367.23566666666665 L 816 372.23566666666665 811 377.23566666666665 806 372.23566666666665 Z" fill="#18abc9"></path>
<path d="M 731 400.91344444444445 L 736 405.91344444444445 731 410.91344444444445 726 405.91344444444445 Z" fill="#18abc9"></path>
<path d="M 651 386.432 L 656 391.432 651 396.432 646 391.432 Z" fill="#18abc9"></path>
<path d="M 570 390.61766666666665 L 575 395.61766666666665 570 400.61766666666665 565 395.61766666666665 Z" fill="#18abc9"></path>
<path d="M 490 381.09166666666664 L 495 386.09166666666664 490 391.09166666666664 485 386.09166666666664 Z" fill="#18abc9">
</path><path d="M 410 334.905 L 415 339.905 410 344.905 405 339.905 Z" fill="#18abc9"></path></g>

我编写了以下Selenium代码来单击第一个path元素。

代码语言:javascript
复制
List<WebElement> a = driver.findElements(By.xpath("(//*[name()='svg']//*[name()='path' and contains(@fill, '#090')])[1]"));
Actions actionBuilder = new Actions(driver);
actionBuilder.click(a.get(0)).build().perform();

列表a只收到了一条告白。程序在尝试单击时抛出错误。

org.openqa.selenium.WebDriverException:元素在点(904,556.86669921875)不可点击。其他元素将收到单击:<path d="M 801 341.00352 L 806 346.00352 801 351.00352 796 346.00352 Z" fill="#090"></path>

我在错误中提供的路径与我提供的DOM不完全相同。

EN

回答 1

Stack Overflow用户

发布于 2016-09-23 00:12:54

此错误是由于另一个path元素与要单击的路径重叠造成的。我猜路径是奇怪的形状,Selenium试图点击它的中间,最后单击另一条路径。您可以在moveToElement()中尝试Actions,并在正确的情况下使用偏移量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39647582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档