selenium-webdriver - 如何使用硒检查svg元素是否存在
问题描述
我有一个 svg 地图,其中包含一些元素,如矩形、圆形、线条、文本等。我需要检查是否存在特定的圆形元素。它在 findElement 方法本身失败,即无法使用代码定位元素。当我检查元素并在 chrome 中输入我的 xpath 时,我得到了该元素,但是当我在 selenium java 代码中使用这个 xpath 时,它无法找到该元素。我尝试了以下方法:
- 存在=driver.findElements(by).size() != 0;
- 带有 xpath 和 cssSelector 的 findElements 方法
DOM结构:
<circle cx="499.99999999999653" cy="199.00000000000082" r="8" fill="#0000ff" stroke="#ffffff" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></circle><rect x="459.99999999999653" y="206.00000000000082" width="80" height="10" r="0" rx="0" ry="0" fill="#ffffff" stroke="#000" stroke-width="0" opacity="0.65" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); opacity: 0.65;"></rect><text x="499.99999999999653" y="211.00000000000082" text-anchor="middle" font="10px "Arial"" stroke="none" fill="#000000" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); text-anchor: middle; font: bold 10px "Trebuchet MS";" font-weight="bold" font-family="Trebuchet MS"><tspan dy="3.4453125000008242" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">Node 4 Object</tspan></text>
Xpath used : // [name()="svg"]// [name()="text"]// [name()="tspan" and text()="Node 4 Object"]//.. /preceding-sibling:: [位置()=2]
解决方案
推荐阅读
- amazon-ses - Mautic 和 Amazon SES 集成问题
- java - JAXB 与 IDEA + Android 插件上的 dataBinding 冲突
- angular - 错误类型错误:“this.profileService.getUserProfile(...) 未定义”
- angular - keyup 在几个输入字段上输入
- node.js - NodeJs 是否需要公共文件权限才能访问文件?
- node.js - 如何使用 jest 模拟链式函数调用?
- kubernetes - 如何通过 kubernetes 安装 kubernetes
- javascript - 表格无法识别来自 javascript 的数据?
- neural-network - 在验证和测试集中是否需要初始化 lstm 隐藏状态?或者只是将其重置为零
- python - 将链接矩阵转换为邻接矩阵