首页 > 解决方案 > 从空手道列表中删除元素?

问题描述

在使用 scripAll() 获取样式属性值列表后,我需要消除一些。想知道 python 中是否有类似 remove() 的东西可以用于相同的用途。

例子: * def list_colors = ["rgb(245,60,86)", "rgb(245,60,86)", "rgb(245,00,00)", "rgb(245,00,00)" ]

想要从列表中删除 rgb(245,00,00)。我怎样才能在空手道中做到这一点?

谢谢

标签: karate

解决方案


我认为您错过了scriptAll()可以采用第三个“过滤器功能”参数,请参阅文档:https ://github.com/intuit/karate/tree/master/karate-core#scriptall-with-filter

* def list_colors = scriptAll('.my-css', "_.style['display']", x => !x.includes('245,00,00'))

否则请参考 JSON 转换:https ://github.com/intuit/karate#json-transforms

* def filtered = karate.map(list_colors, x => !x.includes('245,00,00'))

推荐阅读