使用Geb在下拉框中更改/选择一个值。

时间:2019-01-24 23:05:07

标签: groovy geb

作为Geb Newb,这令人困惑。在尝试单击组合框/下拉框时,出现以下错误:

“ geb.error.RequiredPageContentNotPresent:所需的页面内容'pages.ecomm.NewEnrollmentPage-> countrySelected:geb.module.Select'不存在”

1。页面看起来像这样 enter image description here

2。这是我的消息来源:

3。测试规范代码,用于选择下拉菜单。出现错误指示“ countrySelected”内容/元素不在页面上?或者我什至不在页面上?

NewEnrollmentPage.groovy

import geb.Page
import geb.module.Select

class NewEnrollmentPage extends Page {


    static url = "/shop/spring/enrollment/start/78867?tagCountry=AN&customerType=D&tagLang=ENU&__checkbox_isPC=true&UNI_TODAY=true&__checkbox_UNI_TODAY=true&clearSession=1"
                // "/shop/spring/enrollment/product/landing"
                // below for mwebs (non-prod) --->v

    //At Checker
    static at  = {
        title == "Enrollment"
    }

    static content = {
        // <navigatorName ><options map> <actual navigator>
        CrInitOrdButton(wait: true) { driver.findElement(By.id($("[id='toProductsPage']"))) }
        countrySelected { $("#countrySelected").module(Select) }
        //Options Map
        /* wait : true
         * required : false
         *
         *
         *
         */
    }
}

test.groovy

class test extends smoke.ecomm.resource.ShopBootStrap {

   def "Select Country"() {
        given:
            at NewEnrollmentPage
        when: "select United States for Country"
            **countrySelected.value('US')**

    .
    .
    .

    }

}

1 个答案:

答案 0 :(得分:2)

您的选择器不正确。您正在选择使用countrySelected的ID,但这是元素的名称,其ID实际上是countries。因此,您需要将内容定义更改为:

countrySelected { $("#countries").module(Select) }

countrySelected { $(name: "countrySelected").module(Select) }