需要存储表的属性值以便在空手道中进行断言 [英] Need to store attribute values of a table for assertion in Karate
问题描述
我遇到一种情况,即定位器没有文本值,但是它的名为title的属性具有我需要声明的文本值.在为其编写自定义定位符时,我只能得到文本值".而不是特定的属性值,例如title ="#abcdd".
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".
示例:
<div class="table-cell" role="cell" table-field= "risk" title="high">high</div>
具有 high
作为我可以获得的值
Has high
as value which I can get
鉴于,
<div class="table-cell" role="cell" table-field= "colour" title="#abcdd"></div>
没有任何文本值,但在这种情况下需要获取标题属性值 #abcdd
.
Doesn't have any text value but need to get title attribute value #abcdd
in this case.
需要通用代码才能获取此表中存在的所有此类标题属性值.哪里出了问题?有什么办法我可以解决吗?还是该文本值需要包含在html中?
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.
推荐答案
要获取属性: https://github.com/intuit/karate/tree/master/karate-core#attribute
* def temp = attribute('.table-cell', 'title')
如果您有 Element
引用,则可以在其上调用 .attribute('title')
: https://github.com/intuit/karate/tree/master/karate-core#chaining
And if you have an Element
reference, you can call .attribute('title')
on it: https://github.com/intuit/karate/tree/master/karate-core#chaining
但是请记住,您可以随时在任何元素上调用DOM JS API.因此,我将其作为家庭作业供您弄清楚如何获得
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.
请确保您已阅读有关带过滤器的 locateAll()
的信息,例如: https://stackoverflow.com/a/63894989/143475
Make sure you read about locateAll()
with filter, for example: https://stackoverflow.com/a/63894989/143475
另请参见: https://stackoverflow.com/a/66900081/143475
这篇关于需要存储表的属性值以便在空手道中进行断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!