简体   繁体   English

groovy.lang.MissingPropertyException:没有这样的属性:类的列数:Script1

[英]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.

相关问题 Jenkins groovy.lang.MissingPropertyException:没有这样的属性:对于类:Script1 - Jenkins groovy.lang.MissingPropertyException: No such property: for class: Script1 groovy.lang.MissingPropertyException:没有这样的属性:类经理:Script1 - groovy.lang.MissingPropertyException: No such property: manager for class: Script1 错误:groovy.lang.MissingPropertyException没有这样的属性:sql对于类:Script9 - error: groovy.lang.MissingPropertyException No such property: sql for class: Script9 groovy.lang.MissingPropertyException:没有这样的属性:类的getTestCaseByName: - groovy.lang.MissingPropertyException: No such property: getTestCaseByName for class: groovy.lang.MissingPropertyException:没有此类属性: - groovy.lang.MissingPropertyException: No such property: groovy.lang.MissingPropertyException:没有这样的属性:类的脚本:groovy.lang.Binding - groovy.lang.MissingPropertyException: No such property: script for class: groovy.lang.Binding groovy.lang.MissingPropertyException:没有这样的属性:类的工具包:custom.SampleKeyword - groovy.lang.MissingPropertyException: No such property: Toolkit for class: custom.SampleKeyword groovy.lang.MissingPropertyException:没有这样的属性:任何类:WorkflowScript - groovy.lang.MissingPropertyException: No such property: any for class: WorkflowScript groovy.lang.MissingPropertyException:否这样的属性:类:CustomerCommonRequestBean的getBtnRCR - groovy.lang.MissingPropertyException: No such property: getBtnRCR for class: CustomerCommonRequestBean Mule Anypoint Studio groovy.lang.MissingPropertyException:没有这样的属性:class 的 StringEscapeUtils - Mule Anypoint Studio groovy.lang.MissingPropertyException: No such property: StringEscapeUtils for class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM