selenium svg标签定位元素

特殊的元素定位:svg,frame

SVG 指可伸缩矢量图形 (Scalable Vector Graphics)

需要xpath里面的name()方法:*[name()='svg']

从svg元素开始,下面的元素都要以  *[name()='svg'] 这种形式进行编写,需要通过 name 属性来进行定位。selenium在执行的时候才能够捕获到元素信息。

如果要同时需要该元素的其它属性可以用 and 的方式来进行定位。
写法如下:
//*[name()="svg" and @version="1.1"]//*[name()="image"]

 
get nodeLine() {
return '//div[@id="__map0-innerscroller"]/*[name()="svg"]/*[name()="g"]/*[name()="g"]/*[name()="g"][7]/*[name()="path"][2]';
}
 

verifyNodeLine() {
let selector = $(this.nodeLine);
if (selector.isDisplayed) {
selector.moveTo();
reportLog.attachScreenshot();
if ($(this.contextMenu.activePopover).isDisplayed()) {
return true;
}
}
return false;
}

进阶参考文档:

https://segmentfault.com/a/1190000009556665

https://www.cnblogs.com/tianma3798/p/6653936.html

猜你喜欢

转载自www.cnblogs.com/cherry1130/p/12367443.html