Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to store attribute values of a table for assertion in Karate

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.

like image 255
Uncle Sam Avatar asked Dec 19 '25 09:12

Uncle Sam


1 Answers

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

like image 67
Peter Thomas Avatar answered Dec 21 '25 23:12

Peter Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!