我正在尝试验证SVG下页面上多个元素的填充色。这7个元素的相对Xpath都相同。
// * [@ id =“ svg_health-state-success”] /路径
HTML
<div class="v-object-modifiers hide" xpath="1"> </div>
<svg role="img" class="c-icon c-icon-health-state-success" xpath="1"><use
xlink:href="#svg_health-state-success"></use></svg>
<use xlink:href="#svg_health-state-success"></use>
<svg id="svg_health-state-success" viewBox="0 0 62.5 62.5" width="100%"
height="100%"><path style="fill:#00a651" d="M0 0v62.5h62.5V0H0zm25.7
48.2L9.5 32l8.6-8.6 7.8 8.4 20.9-17.4 6.2 6.4-27.3 27.4z"></path></svg>
<path style="fill:#00a651" d="M0 0v62.5h62.5V0H0zm25.7 48.2L9.5 32l8.6-8.6
7.8 8.4 20.9-17.4 6.2 6.4-27.3 27.4z"></path>
</svg>
</use>
</svg>
</div>
我尝试在脚本上使用以下内容,但它不起作用
String XPATHONE = "//*[name()='svg']//*[name()='path' and @fill='#00a651' and position()=2]";
WebElement svgObj = driver.findElement(By.xpath(XPATHONE));
Actions actionBuilder = new Actions(driver);
actionBuilder.click(svgObj).build().perform();
答案 0 :(得分:1)
fill
不是path
元素的属性,而是它的 CSS样式属性,因此您不能使用@fill
语法。请尝试以下XPath:
//*[name()='svg']//*[name()='path' and contains(@style, 'fill="#00a651"')]
我也不确定position()=2
谓词,因为path
节点似乎没有兄弟姐妹(如果实际上有兄弟姐妹,请正确更新HTML源示例)