【问题标题】:Need to store attribute values of a table for assertion in Karate需要存储表的属性值以在空手道中进行断言
【发布时间】:2021-06-17 10:51:00
【问题描述】:

我有一个情况,定位器没有文本值,但它的名为 title 的属性有一个我需要断言的文本值。在为其编写自定义定位器时,我只能获取文本值“”而不是特定属性值,例如 title = “#abcdd”。

例子:

<div class="table-cell" role="cell" table-field= "risk" title="high">high</div>

我可以得到 high 作为值

然而,

<div class="table-cell" role="cell" table-field= "colour" title="#abcdd"></div>

没有任何文本值,但在这种情况下需要获取标题属性值#abcdd

需要一个通用代码来获取此表中存在的所有此类标题属性值。 哪里出了问题?我有什么办法可以处理这个?或者那个文本值需要包含在 html 中?

使用空手道作为自动化测试工具。

【问题讨论】:

    标签: html ui-automation karate


    【解决方案1】:

    获取属性: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

    但请始终牢记,您可以随时在任何元素上调用 DOM JS API。所以我把它作为一个家庭作业让你弄清楚如何得到Element.attributes 的结果,如果需要,问一个新问题,具体说明你尝试了什么。

    确保您阅读了带有过滤器的locateAll(),例如:https://stackoverflow.com/a/63894989/143475

    另请参阅:https://stackoverflow.com/a/66900081/143475

    【讨论】:

    • 感谢@PeterThomas,scriptAll() 在这种情况下工作得很好!
    猜你喜欢
    • 2021-02-12
    • 2021-08-15
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2019-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多