【发布时间】:2019-03-27 14:45:43
【问题描述】:
这是我需要单击的元素的 HTML 片段,我得到“org.openqa.selenium.InvalidSelectorException”
<svg viewBox="0 12.705 512 486.59" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg" height="20" width="20" style="margin-right:
0px;">
<svg viewBox="0 12.705 512 486.59"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg" height="20" width="20" style="margin-
right: 0px;">
<defs>
<polygon points="256.814,12.705 317.205,198.566 512.631,198.566
354.529,313.435 414.918,499.295 256.814,384.427 98.713,499.295
159.102,313.435 1,198.566 196.426,198.566 " style="fill:
url(#jRate_grad4);stroke:black;fill-opacity:1;stroke-width:2px;">
</svg>
我使用了以下代码:
>WebElement ele = driver.findElement(By.xpath(".//*[@id='jRate']/svg[5]/"));
>JavascriptExecutor js = (JavascriptExecutor)driver;
>js.executeScript("argument[0].click()", ele);
我试图找到该元素并单击它,由于异常,我使用了 JavaScript 并且问题相同。我不知道我在这里错过了什么。
非常感谢 Java 相关的帮助。
【问题讨论】:
-
从
xpath中删除关闭/。 -
还是不行!
-
从 xpath 中删除点并最后关闭 / - 使用它 - //*[@id='jRate']/svg[5]
-
@Dhru'soni 好的,改变了异常“org.openqa.selenium.NoSuchElementException”现在出现在屏幕上。
-
@SaiKrishnaPulivarthi 不要冒犯和批评“版主”,再看看你的问题并问自己“我的问题好吗?我是否分享了足够的信息以获得好的答案?”。我认为答案将是“不”。 This ticket 包含处理 svg 节点的解决方案。您的解决方案(来自评论)也与您的问题不匹配
标签: selenium selenium-webdriver css-selectors