How to locate a tag name inside a div using xpath and Robotframework

Viewed 333

So I am asserting that a particular tag exists in the dom. There is no id or class inside the div so I am using xpath to locate it. I am not sure how to write out the path correctly. The DOM simplified looks as follows

<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]

What do I need to add to that to ensure its looking for data-list and not just the div. There are loads of other tags inside that div that I want to assert separately. 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.

Thanks in advance for all help.

1 Answers

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:

//div[@id="top-list"]/div[@data-list="1"]
Related