我无法单击2图标之间的图标,因为它们具有相同的类名,尽管它具有两个不同的xpath但xpath不是内容处理程序,因此findElement(By.xpath())注释不起作用。以下是HTML
的区别class="doughnut-clicker-circle" questiontype="hypothetical"
class="doughnut-clicker-circle" questiontype="multichoice"
唯一不同的是问题类型。有人能告诉我如何在selenium + Java中找到元素。
<svg>
<circle class="doughnut-clicker-circle" questiontype="multichoice" learningobjid="dfe00abe-cef8-11e3-8be9-67ee60a9f4aa" learningobjname="Determine whether trespassers have a right to capture property." data-action="/assessmentRetrievalService/getQuestionForStudyCenterLearn" data-handler="loadStudyCenter" fill="transparent" r="48" cy="53" cx="53">
Sorry, your browser does not support inline SVG.
</svg>
<svg>
<circle class="doughnut-clicker-circle" questiontype="hypothetical" learningobjid="dfe00abe-cef8-11e3-8be9-67ee60a9f4aa" learningobjname="Determine whether trespassers have a right to capture property." data-action="/assessmentRetrievalService/getQuestionForStudyCenterLearn" data-handler="loadStudyCenter" fill="transparent" r="48" cy="53" cx="53">
Sorry, your browser does not support inline SVG.
</svg>
答案 0 :(得分:0)
您可以使用标识符组合找到这些元素。我们可以按类和属性值说,例如//*[@class='doughnut-clicker-circle' and @questiontype='hypothetical']
和//*[@class='doughnut-clicker-circle' and @questiontype='multichoice']
。
答案 1 :(得分:0)
自从我在Java下使用Selenium后发布Java代码(希望这对您的情况有帮助):
@FindBy(how = How.CSS, using = "circle[questiontype*='multichoice']")
private WebElement circle;
基本上,您需要在以下CSS之后找到一个元素:
"circle[questiontype*='multichoice']"
表示circle
标记的属性questiontype
的值为multichoice
(该值必须包含字符串multichoice
不等于它。)