Reputation: 255
I have a case where locator doesn't have a text value but it's attribute named title has a text value that I need to assert. While writing custom locator for it I can only get the text value which is "" and not specific attribute value say title = "#abcdd".
Example:
<div class="table-cell" role="cell" table-field= "risk" title="high">high</div>
Has high
as value which I can get
Whereas,
<div class="table-cell" role="cell" table-field= "colour" title="#abcdd"></div>
Doesn't have any text value but need to get title attribute value #abcdd
in this case.
Need a generic code to get all such title attribute values present inside this table. Where are the things going wrong? Any way I can handle this? Or that text value needs to be included in html?
Using karate as Automation test tool.
Upvotes: 3
Views: 1352
Reputation: 58088
To get an attribute: https://github.com/intuit/karate/tree/master/karate-core#attribute
* def temp = attribute('.table-cell', 'title')
And if you have an Element
reference, you can call .attribute('title')
on it: https://github.com/intuit/karate/tree/master/karate-core#chaining
But always keep in mind you can call the DOM JS API on any element, any time. So I leave it as a homework for you to figure out how to get the results of Element.attributes
, ask a new question with specifically what you tried if needed.
Make sure you read about locateAll()
with filter, for example: https://stackoverflow.com/a/63894989/143475
And also see this: https://stackoverflow.com/a/66900081/143475
Upvotes: 1