在 groovy 个页面中使用 findElement
Using findElement in groovy pages
抱歉,如果这个问题看起来微不足道,..但我对 groovy/selenium 非常陌生,作为 Maven 系统的一部分,我已经被抛出,我需要了解我在尝试中遗漏了什么让这个方法起作用。
我收到的错误如下:
groovy.lang.MissingMethodException: No signature of method: GebConfig.findElement() is applicable for argument types: (org.openqa.selenium.By$ByName)
我需要在网页上定位元素并想使用 findElement 方法,但是我的代码在 groovy 中作为步骤定义的一部分。
经过多次尝试,我得到了以下结果,但一无所获:
package step_definitions
import features.support.Requests
import geb.*
import org.apache.commons.io.*
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.*
import org.openqa.selenium.remote.*
import cucumber.api.groovy.EN.*
When(~/^find the element named "(.*?)"$/) { String btnName ->
WebElement myElement = driver.findElement(By.name(btnName));
}
我知道我可以将类似下面的内容用于按钮,将类似的内容用于单选按钮和输入字段等其他内容:
browser.$(‘input’, name: ‘btnK’)
$(‘input’, name: ‘btnK’)
但我更想知道如何使用 findElement 方法。
如有任何帮助,我们将不胜感激。
谢谢,
吉姆……
我看到您正在将 Geb 与 Cucumber JVM 一起使用。如果您已按照 http://gebish.org/manual/current/#writing-your-own-steps then the methods and properties available in your steps are as listed in http://gebish.org/manual/current/#browser-methods-and-properties 中所述使用 geb.binding.BindingUpdater
设置了环境。您会注意到该列表中没有 driver
属性 - 如果您希望访问驱动程序实例,则必须从 browser
:
获取它
When(~/^find the element named "(.*?)"$/) { String myName ->
WebElement myElement = browser.driver.findElement(By.name(btnName));
}
抱歉,如果这个问题看起来微不足道,..但我对 groovy/selenium 非常陌生,作为 Maven 系统的一部分,我已经被抛出,我需要了解我在尝试中遗漏了什么让这个方法起作用。
我收到的错误如下:
groovy.lang.MissingMethodException: No signature of method: GebConfig.findElement() is applicable for argument types: (org.openqa.selenium.By$ByName)
我需要在网页上定位元素并想使用 findElement 方法,但是我的代码在 groovy 中作为步骤定义的一部分。 经过多次尝试,我得到了以下结果,但一无所获:
package step_definitions
import features.support.Requests
import geb.*
import org.apache.commons.io.*
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.*
import org.openqa.selenium.remote.*
import cucumber.api.groovy.EN.*
When(~/^find the element named "(.*?)"$/) { String btnName ->
WebElement myElement = driver.findElement(By.name(btnName));
}
我知道我可以将类似下面的内容用于按钮,将类似的内容用于单选按钮和输入字段等其他内容:
browser.$(‘input’, name: ‘btnK’)
$(‘input’, name: ‘btnK’)
但我更想知道如何使用 findElement 方法。
如有任何帮助,我们将不胜感激。
谢谢,
吉姆……
我看到您正在将 Geb 与 Cucumber JVM 一起使用。如果您已按照 http://gebish.org/manual/current/#writing-your-own-steps then the methods and properties available in your steps are as listed in http://gebish.org/manual/current/#browser-methods-and-properties 中所述使用 geb.binding.BindingUpdater
设置了环境。您会注意到该列表中没有 driver
属性 - 如果您希望访问驱动程序实例,则必须从 browser
:
When(~/^find the element named "(.*?)"$/) { String myName ->
WebElement myElement = browser.driver.findElement(By.name(btnName));
}