Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Selenium 如何使用类和HTML标记位置识别XPath_Selenium_Xpath_Selenium Ide - Fatal编程技术网

Selenium 如何使用类和HTML标记位置识别XPath

Selenium 如何使用类和HTML标记位置识别XPath,selenium,xpath,selenium-ide,Selenium,Xpath,Selenium Ide,我不熟悉seleniumide。正在尝试使用具有相同值的类获取第二个html标记 <div class="test"> <div> <small class="jo-date-time text-muted">Ordered on Jun 23, 2016 </small> </div> </div> <div class="test"> <div> <small class="jo-date-

我不熟悉
seleniumide
。正在尝试使用具有相同值的类获取第二个html标记

<div class="test">
<div>
<small class="jo-date-time text-muted">Ordered on Jun 23, 2016 </small>
</div>
</div>
<div class="test">
<div>
<small class="jo-date-time text-muted">Ordered on Jun 22, 2016 </small>
</div>
</div>

2016年6月23日订购
2016年6月22日订购
e、 g。
class=jo日期时间[2]和//small[@class='jo-date-time'][2]

但是,它不起作用。它仍然需要父html标记。真的是这样吗


这个适合我。->
//div[@class='test'][2]/div/small

这些XPath无法工作,因为它们不正确

如果注意到
class
属性,则会出现一个空格,然后是您忽略的文本。这就是它不起作用的原因

更改自:
//small[@class='jo-date-time'][2]

至:
(//small[@class='jo-date-time text-muted'])[2]

我个人不使用索引,因为如果有办法避免,索引可能会有所不同

以下是避免使用索引的另一种方法:

//small[@class='jo-date-time text muted'和.='Ordered on Jun 22,2016']

如果要按类名定位元素jo-date-time
然后尝试在xpath中包含函数

//small[contains(@class,'jo-date-time')][2]

我尝试使用(//small[@class='jo-date-time text muted'])[2],尽管它仍然不起作用。我使用索引的原因是数据是动态的,可能会更改。我只是想看看他们是否在场。顺便问一下,它真的应该用()括起来吗?@LovieT,你想提供更多细节吗?你是如何使用它的?我提供的是一个测试结果