在空手道中包含重复元素的表上执行通配符操作? [英] Performing wildcard operations on table containing duplicate elements in karate?

查看:46
本文介绍了在空手道中包含重复元素的表上执行通配符操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持要求用户断言输入后单击图标的情况.万一有一些唯一的标识符,事情就很简单,就像使用: rightOf('{} UniqueIdentifier').find('i').click()达到了目的.也可以正常使用: scroll('{} UniqueIdentifier').parent.children [4] .click()

I am stuck with a case where the need is to click on an icon after asserting inputs from the user. In case there were some unique identifiers, the thing was pretty simple like the use of: rightOf('{}UniqueIdentifier').find('i').click() served the purpose. Also working fine with: scroll('{}UniqueIdentifier').parent.children[4].click()

但是,如果表包含重复的值,则找不到唯一可搜索和单击的内容.对于这种想法是要匹配整个行文本,其中最后一个元素是需要单击的图标,或者其他适合的方法?

But in case the table contains repeated values nothing could be found unique to search for and click. For which the thought was to match entire row text where the last element is that icon which needs to be clicked OR any other method which suits this?

表如下所示:-

Table looks like this:-

需要单击三点图标-A2,P2、2已解决.使用通配符定位符如何实现?我尝试创建元素列表并将其与用户输入列表匹配,但是这样做失败.

Need to click on triple dot icon for- A2,P2,2,resolved. How can this be achieved using wildcard locators? I tried creating a list of elements and match it with user input list but failed doing so.

任何帮助将不胜感激.谢谢!

Any help would be appreciated. Thanks!

推荐答案

首先,您应该对 locateAll()感到满意.它将返回一个 Element 对象的数组.之后,有许多种可能的方法可以遍历并找到您想要的东西.

First you should get comfortable with locateAll(). It will return an array of Element objects. And after that there are many possible ways of looping over and finding what you want.

还要注意,这里有一个带有过滤器的" locateAll()":

Also note that there is a "locateAll() with filter": https://github.com/intuit/karate/tree/master/karate-core#locateall-with-filter

由于您还没有提供任何HTML,因此我不得不猜测.请注意,下面的 x 是一个 Element ,您甚至可以在其上调用 locate().

Since you haven't provided any HTML I will have to guess. And note that x below is an Element and you can even call locate() on it.

* def filter = function(x){ x.text.contains('Unique Identifier') }
* def list = locateAll('.grand-parent-class', filter)
* list[0].parent.children[4].click()

这篇关于在空手道中包含重复元素的表上执行通配符操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆