Apologies if this question seems trivial,.. but I am very very new to groovy/selenium as part of a maven system I’ve been thrown at and am in need to understand what I am missing in trying to get this method to work.
The error I am getting is below:
groovy.lang.MissingMethodException: No signature of method: GebConfig.findElement() is applicable for argument types: (org.openqa.selenium.By$ByName)
I’m in need to locate elements on a web page and would like to use the findElement method, however my code is in groovy as part of step definitions. I have ended up with the following after lots of attempts but am getting nowhere:
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));
}
I know I can use things like the below for a button and similar for other things like radio buttons and input fields:
browser.$(‘input’, name: ‘btnK’)
$(‘input’, name: ‘btnK’)
But I’d prefer to know how to use the findElement approach.
Any help would be appreciated.
Thanks,
Jim…..
I can see that you are using Geb with Cucumber JVM. If you've setup your environment using geb.binding.BindingUpdater
as described in 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. You will notice that there is no driver
property in that list - if you wish to access the driver instance then you will have to obtain it from browser
:
When(~/^find the element named "(.*?)"$/) { String myName ->
WebElement myElement = browser.driver.findElement(By.name(btnName));
}