[英]How to locate a tag name inside a div using xpath and Robotframework
So I am asserting that a particular tag exists in the dom.所以我断言 dom 中存在一个特定的标签。 There is no id or class inside the div so I am using xpath to locate it.
div 中没有 id 或 class,所以我使用 xpath 来定位它。 I am not sure how to write out the path correctly.
我不确定如何正确写出路径。 The DOM simplified looks as follows
DOM 简化如下所示
<div id="top-list">
<div data-version="12345" data-list="1" data-point="10">
I want to assert that data-list
exists but the xpath it suggests for me to find that tag is //*[@id="top-list"]/div[1]
我想断言
data-list
存在,但它建议我找到该标签的 xpath 是//*[@id="top-list"]/div[1]
What do I need to add to that to ensure its looking for data-list
and not just the div.我需要添加什么以确保它寻找
data-list
而不仅仅是 div。 There are loads of other tags inside that div that I want to assert separately.该 div 中有很多其他标签,我想单独断言。 I am just showing one or two to keep things easy to read.
我只是展示一两个以使事情易于阅读。
I tried an xpath like //*[@id="top-list"]/div[1]["data-list"]
and a few other variations of that, but I can't seem to find the correct path.我尝试了像
//*[@id="top-list"]/div[1]["data-list"]
这样的 xpath 以及其他一些变体,但我似乎找不到正确的路径。
Thanks in advance for all help.在此先感谢所有帮助。
If you want to locate node with specific attribute this one should do the trick:如果你想找到具有特定属性的节点,这个应该可以解决问题:
//div[@id="top-list"]/div[@data-list]
You can also specify @data-list
value in XPath:您还可以在 XPath 中指定
@data-list
值:
//div[@id="top-list"]/div[@data-list="1"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.