从List< WebElement>获取文本在Groovy [英] Get text from List<WebElement> in Groovy

查看:156
本文介绍了从List< WebElement>获取文本在Groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理实现groovy lambda函数的问题,该函数将文本从List集合转换为List集合. 原始的Java代码:

I am dealing with problem to implement groovy lambda function getting text from List collection into List collection. The original java code:

list.stream().map(WebElement::getText).collect(Collectors.toList());

我的Groovy版本失败:

My Groovy version fails:

list.stream().map({ WebElement } as String).collect(Collectors.toList())

groovy.lang.MissingMethodException:没有方法的签名: java.util.stream.ReferencePipeline $ Head.map()适用于 参数类型:(java.lang.String)值: [quality1.CommonMethods$_clickSubMenuLeftBar_closure2@4e49ce2b] 可能的解决方案:map(java.util.function.Function), max(java.util.Comparator),min(java.util.Comparator),wait(),grep(), any()–

groovy.lang.MissingMethodException: No signature of method: java.util.stream.ReferencePipeline$Head.map() is applicable for argument types: (java.lang.String) values: [quality1.CommonMethods$_clickSubMenuLeftBar_closure2@4e49ce2b] Possible solutions: map(java.util.function.Function), max(java.util.Comparator), min(java.util.Comparator), wait(), grep(), any() –

有人可以帮助我如何使其正常工作吗?我正在尝试使用类似的方法,例如: http://mrhaki.blogspot.com/2015/04/groovy-goodness-use-closures-as-java.html ,但没有成功.

Can anybody help me how to make it working? I was trying to use similar approach like here: http://mrhaki.blogspot.com/2015/04/groovy-goodness-use-closures-as-java.html but without success.

推荐答案

Groovy 3.0 (当前版本:3.0.0-alpha-3)由于使用了新的鹦鹉,将支持lambda表达式和方法引用解析器- http://groovy-lang.org/releasenotes/groovy-3.0.html

Groovy 3.0 (current version: 3.0.0-alpha-3) will support lambda expressions and method references thanks to a new parrot parser - http://groovy-lang.org/releasenotes/groovy-3.0.html

对于Groovy 2.5.x和更早的版本,您将不得不替换方法参考:

For Groovy 2.5.x and older you will have to replace method reference:

WebElement::getText

带结束符:

{ el -> el.getText() }

最终的工作示例应如下所示:

Final working example should look like this:

list.stream().map{ el -> el.getText() }.collect(Collectors.toList())

这篇关于从List< WebElement>获取文本在Groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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