【问题标题】:GEB - How to get value from readonly inputGEB - 如何从只读输入中获取价值
【发布时间】:2018-01-25 15:04:59
【问题描述】:

我正在尝试从只读输入中获取值,如下所示:

<input id="EmailGeneratorText" class="input-email-input" readonly="" placeholder="Generated email"/>

我尝试如下:

def a = js.exec 'jQuery("input#EmailGeneratorText").val()' 

但不幸的是它没有帮助

System.out.println("value:" + a) // => value:null**

我也尝试了 .text() 和 .value(),但没有结果。 有人可以帮我吗?

【问题讨论】:

    标签: jquery groovy spock geb


    【解决方案1】:

    这应该可行:

    element.@value
    

    假设它有一个值......在你的示例 html 中,它没有一个

    【讨论】:

    • 感谢您的回答,但它不起作用。这就是问题所在,在 html 中值属性未公开,输入看起来与示例完全相同,但 UI 上的输入填充了一个字符串,在我的情况下是生成的电子邮件。我试图检查浏览器控制台,我注意到 $('#EmailGeneratorText').value() 和 $('#EmailGeneratorText').text() 不会从输入返回值,只有 $('#EmailGeneratorText' ).val() 确实如此。但是这种情况下如何让geb执行jquery呢?
    • 你试过def a = js.exec('return $("#EmailGeneratorText").val();')是吗?
    • return? (您的问题中没有return
    • 你确定输入在你得到它的时候一个值吗?如果它是由 UI 异步设置的,你可能只是太快了?尝试将您的支票放入waitFor { ... }
    • 没用。这是我的第一个想法,这是我的方法的外观: def generateEmail(){ asmEmailGeneratorButton.click() waitFor {asmEmailGeneratorText} def a = js.exec('return $("input#asmEmailGeneratorText").val();' )}
    【解决方案2】:

    试试这个:

     println   $("input",id:"EmailGeneratorText",class:"input-email-input").value()
    

    一定会成功的

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 2022-01-05
      • 1970-01-01
      相关资源
      最近更新 更多