Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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 PhantomJS中通过完整xPath查找元素_Java_Selenium_Xpath_Webdriver_Phantomjs - Fatal编程技术网

Java 如何在Selenium PhantomJS中通过完整xPath查找元素

Java 如何在Selenium PhantomJS中通过完整xPath查找元素,java,selenium,xpath,webdriver,phantomjs,Java,Selenium,Xpath,Webdriver,Phantomjs,我想通过xPath查找我刚从浏览器HTML查看器复制的元素。有什么好的使用方法吗?如何定位此元素 例如: 1) HTML <span class="fifth-star star-common" data-star-index="5" jsaction="click:JdtzLb;mouseenter:UYGLjf"> </span> <a class="actionlink" href="javascript:CCommentThread.DeleteComme

我想通过xPath查找我刚从浏览器HTML查看器复制的元素。有什么好的使用方法吗?如何定位此元素

例如:

1) HTML

<span class="fifth-star star-common" data-star-index="5" jsaction="click:JdtzLb;mouseenter:UYGLjf"> </span>
<a class="actionlink" href="javascript:CCommentThread.DeleteComment( 'PublishedFile_Public_76561198045856086_852822766_0', '133257324794187128' );">Удалить</a>
(二) HTML

<span class="fifth-star star-common" data-star-index="5" jsaction="click:JdtzLb;mouseenter:UYGLjf"> </span>
<a class="actionlink" href="javascript:CCommentThread.DeleteComment( 'PublishedFile_Public_76561198045856086_852822766_0', '133257324794187128' );">Удалить</a>
我试过这样做

还有这个

driver.findElement(By.xpath("//*[@id=\"comment\"]/div[2]/div[1]/a[2]"));

在XPATH中使用
单引号
,而不是使用
\

试着这样做:

driver.findElement(By.xpath("//*[@id='comment']/div[2]/div[1]/a[2]"));
请共享块代码,以防更高效的
XPATH


其他途径:

driver.findElement(By.xpath("//a[starts-with(@href,'javascript:CCommentThread.DeleteComment')]"));

好的方法是,您还需要共享HTML…:)@Saurabh Gaur DoneIs这两个元素HTML都是唯一的吗??若不仅元素的HTML不足以唯一地定位它,还需要共享HTML块。谢谢..:)
ReferenceError:By没有在您的代码
org.openqa.selenium.By
driver.findElement(By.xpath("//a[starts-with(@href,'javascript:CCommentThread.DeleteComment')]"));