[英]groovy.lang.MissingPropertyException: No such property: Cols for class: Script1
i have a list like below我有一个像下面这样的清单
List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))
I have a method like below我有一个像下面这样的方法
public def queryGenerator(Map inputs)
{
def firstvalue = 'Cols.get('
def Secondvalue = ').getText().equals('
def thirdvalue = ')'
def ampersand = '&'
def value = ''
inputs.each({ def k, def v ->
int inum = Integer.parseInt(k);
value = value + firstvalue+(inum-1)+Secondvalue+"\'$v\'"+thirdvalue+ampersand
})
return value.substring(0, value.length()-1)
}
Now I am going to use Eval from groovy to convert this expression现在我将使用 groovy 中的 Eval 来转换这个表达式
String x = queryGenerator(values) //This will return Cols.get(0).getText().equals("some value")
if(Eval.me(x){}
This gives following error这给出了以下错误
groovy.lang.MissingPropertyException: No such property: Cols for class: Script1
I have checked the groovy documentation most of Eval are using String, Object and Expression.我已经检查了大多数 Eval 使用字符串、对象和表达式的 groovy 文档。 Is there any way so that Eval can recognise the list.有什么办法可以让 Eval 识别列表。
One possible explanation is that you are running this from a groovy script (ie just a xxx.groovy
file with code directly in the file without any class
declarations).一种可能的解释是您正在从一个 groovy 脚本(即,只是一个xxx.groovy
文件,代码直接在文件中,没有任何class
声明)运行它。 If so, please see for example this stackoverflow answer for information on the scoping of variables in groovy scripts.如果是这样,请参阅例如此 stackoverflow 答案以获取有关 groovy 脚本中变量范围的信息。
Long story short, you this is a groovy script you can try:长话短说,你这是一个可以尝试的常规脚本:
Cols = Rows.get(i).findElements(By.tagName('td'))
(ie without the initial type declaration) or (即没有初始类型声明)或
import groovy.transform.Field
...
@Field List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.