【问题标题】:Geb setting Values to Select issueGeb设置值选择问题
【发布时间】:2013-08-08 14:57:48
【问题描述】:

我无法从列表框中选择值

<select name="max">
    <option value="25">25</option>
    <option value="50" selected="selected">50</option>
    <option value="100">100</option>
</select>

在我的页面中,我有:

class TableSectionModule extends Module {

    static base = { $('#runList') }

    static content = {
               tablePaginationSelect { $("select", name : "max") }
    }
}

我在我的规范中使用了所有这些调用:

runs.table.tablePaginationSelect = "100"

我也试过这个:

 runs.table.tablePaginationSelect.value('100')

但我有一个例外

org.openqa.selenium.WebElement.setSelected()V
java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.setSelected()V
    at org.openqa.selenium.support.ui.Select.selectByValue(Select.java:176)
    at geb.navigator.NonEmptyNavigator.setSelectValue(NonEmptyNavigator.groovy:591)
    at geb.navigator.NonEmptyNavigator.setInputValue(NonEmptyNavigator.groovy:548)
    at geb.navigator.NonEmptyNavigator.setInputValues_closure33(NonEmptyNavigator.groovy:542)
    at geb.navigator.NonEmptyNavigator.setInputValues(NonEmptyNavigator.groovy:541)
    at geb.navigator.NonEmptyNavigator.value(NonEmptyNavigator.groovy:319)
    at geb.content.NavigableSupport.methodMissing(NavigableSupport.groovy:123)
    at geb.content.NavigableSupport.propertyMissing(NavigableSupport.groovy:141)

我正在使用带有 Geb 的 Grails,这是我正在使用的依赖项:

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.

        // runtime 'mysql:mysql-connector-java:5.1.22'

        test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")
        test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")

        // You usually only need one of these, but this project uses both
        //test "org.codehaus.geb:geb-spock:$gebVersion"
        test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
        test "org.gebish:geb-spock:0.9.0"
        test "org.codehaus.geb:geb-spock:0.7.2"
        test "org.seleniumhq.selenium:selenium-support:2.0a7"

    }

【问题讨论】:

    标签: testing selenium spock geb


    【解决方案1】:

    .value('100') 语法是正确的。我使用了一个示例 gradle+geb(因此没有 Grails,因此依赖项略有不同)项目,重新创建了您的下拉列表和模块,并且能够使用这种语法对其产生影响。

    尝试不使用Module。完全绕过它,看看它会给你什么:

    $('select' name:'max').value('100')
    

    更新

    这是我在屏幕上观察发生的变化时所做的(通过几个健全性检查 println 的):

        def sel = $('select', name:'max')
        sel.size() == 1
        System.out.println(sel.getClass().name)
        System.out.println(sel)
        System.out.println(sel.value())
        Thread.sleep( 500 )
        sel.value ( "25"  )
        Thread.sleep( 500 )
        sel.value ( "50")
        Thread.sleep( 500 )
        sel.value ( "100")
        Thread.sleep( 500 )
        System.out.println(sel.value())
    

    此外,一旦您的测试完成,请务必查看您的测试输出。对于我自己,那是在build/test-results。此外,您可以在 gradle 上启用调试输出:gradlew build --debug。这可能很有帮助。

    【讨论】:

    • 感谢加布里埃尔的回复。我不再有错误但现在没有任何反应......选择框没有改变。有什么想法吗?
    • 我用更多建议更新了我的答案。希望里面的东西会动摇。
    • 你也可以考虑更新你的 selenium 依赖。看起来您正在使用 alpha 版本 (2.0a7)。他们最多可达2.33.0
    • 嘿,谢谢 Gabriel...我不得不将 selenium 支持的版本更改为 2.33.0..现在它可以与 .value('100') 一起使用
    猜你喜欢
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 2016-07-25
    • 2020-12-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    相关资源
    最近更新 更多