Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在selenium中定位对象_Java_Selenium_Xpath_Selenium Webdriver - Fatal编程技术网

Java 如何在selenium中定位对象

Java 如何在selenium中定位对象,java,selenium,xpath,selenium-webdriver,Java,Selenium,Xpath,Selenium Webdriver,我无法单击2个图标之间的图标,因为这两个图标都有相同的类名,尽管它有两个不同的xpath,但xpath没有内容处理程序,因此findElementBy.xpath注释不起作用。下面是HTML的区别 class="doughnut-clicker-circle" questiontype="hypothetical" class="doughnut-clicker-circle" questiontype="multichoice" 唯一的区别是问题类型。有人能告诉我如何在selenium+

我无法单击2个图标之间的图标,因为这两个图标都有相同的类名,尽管它有两个不同的xpath,但xpath没有内容处理程序,因此findElementBy.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>

您可以使用标识符的组合来查找这些元素。比如说,按类和属性值,例如//*[@class='doughnut-clicker-circle'和@questiontype='假想']和//*[@class='doughnut-clicker-circle'和@questiontype='multichoice'])。

将发布一段Java代码,因为我在Java hope下使用了Selenium,这对您的情况有帮助:

@FindBy(how = How.CSS, using = "circle[questiontype*='multichoice']")
private WebElement circle;
基本上,您需要在以下CSS之后找到一个元素:

圈[questiontype*='multichoice']


表示具有值为multichoice的questiontype属性的圆圈标记。该值必须包含字符串multichoice,且不等于该值。

能够启动Hypo-question,但不能使用相同的代码执行多项选择。driver.findElementBy.xpath./*[@class='doughnut-clicker-circle'和@questiontype='multichoice'];您确定在单击Hypo元素后元素Multiple没有更改吗?我正在运行两个不同的测试用例,分别用于多项选择和Hypo。因此,当我输入driver.findElementBy.xpath./*[@class='doughnut-clicker-circle'和@questiontype='multichoice']时,单击;它无法找到元素。如果您运行与“hypo”相关的测试作为第一个测试,该怎么办?这个元素在哪里?