Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 如何在下面的Html代码中识别定位器,以及如何在selenium中为此编写xpath?_Java_Selenium_Xpath - Fatal编程技术网

Java 如何在下面的Html代码中识别定位器,以及如何在selenium中为此编写xpath?

Java 如何在下面的Html代码中识别定位器,以及如何在selenium中为此编写xpath?,java,selenium,xpath,Java,Selenium,Xpath,如何在下面的Html中识别定位器以及如何为其编写xpath 这是硒 <div> <div class="slds-icon-waffle" data-aura-rendered-by="231:0;p"> <div class="slds-r1" data-aura-rendered-by="232:0;p"></div> <div class="slds-r2" data-aura-rendered-by="233:0;p">

如何在下面的Html中识别定位器以及如何为其编写xpath 这是硒

 <div>    
<div class="slds-icon-waffle" data-aura-rendered-by="231:0;p">
<div class="slds-r1" data-aura-rendered-by="232:0;p"></div>
<div class="slds-r2" data-aura-rendered-by="233:0;p"></div>
<div class="slds-r3" data-aura-rendered-by="234:0;p"></div>
<div class="slds-r4" data-aura-rendered-by="235:0;p"></div>
<div class="slds-r5" data-aura-rendered-by="236:0;p"></div>
<div class="slds-r6" data-aura-rendered-by="237:0;p"></div>
<div class="slds-r7" data-aura-rendered-by="238:0;p"></div>
<div class="slds-r8" data-aura-rendered-by="239:0;p"></div>
<div class="slds-r9" data-aura-rendered-by="240:0;p"></div> 
</div>

您可以使用div类生成xpath,如下所示:

   //div[contains(@class,'slds-icon-waffle')]

希望它能帮助您。

这里的类名看起来很独特。您可以使用以下xpath来标识第一个元素

//div[@class="slds-icon-waffle"]
对于第二个元素

//div[@class=“slds-r1”]
等等

如果要使用单个xpath查找所有元素,请使用以下命令

//div[starts-with(@class,"slds")]

在selenium中编写xpath是一件非常基本的事情。我希望您先学习如何编写xpath。这段视频可能会给你一些想法


一旦你有了一些想法,试着自己编写xpath。如果您有任何问题,请随时发表评论。谢谢。

你知道Chromes通过在浏览器中检查元素来生成xpath的能力吗?不知道。你能帮我一下吗。在google chrome中:
右键单击>检查
然后选择节点并
右键单击>复制>复制xpath
我检查了它,并复制为X路径。有了这些,我已经用类和链接文本编写了xpath。“这不起作用。”SreEdHeShanthkaMar,你能考虑一下展示一下你的作品吗?当然谢谢,当然谢谢。