import java.io.IOException;
import geb.Browser
import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
public class Signin {
def browser = new Browser()
def driver
public launch() throws IOException {
browser.driver = new FirefoxDriver()
browser.go"http://www.gmail.com/"
sleep(1000)
println "First Class completed"
}
}
import geb.Browser;
import java.io.IOException;
import Signin
class Main {
static main(args) throws IOException {
Signin first =new Signin()
first.launch()
sleep(1000)
Search third =new Search()
third.search()
}
}
import geb.Browser
import java.io.IOException;
import org.openqa.selenium.WebElement
import org.openqa.selenium.By.ByXPath;
import org.openqa.selenium.WebElement.*;
import org.openqa.selenium.firefox.FirefoxDriver
import geb.*
import Signin
class Search extends Signin {
def elementToClick
void search() throws IOException {
sleep(1000)
println"search class"
wait(1000)
WebElement myaccount =browser.$("a", title: "my account")
myaccount.click()
// WebElement elementToClick = driver.$("a", title:"searchTerm");
// elementToClick.click()
browser.$("input", id:"searchTerm").value("abi")
sleep(1000)
//driver.findElement(By.xpath("//*[@id=\"pay-now\"]")).click();
println "Search class completed"
}
}
輸出::
First Class completed
search class
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'geb.navigator. EmptyNavigator' to class 'org.openqa.selenium.WebElement'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'geb.navigator.EmptyNavigator' to class 'org.openqa.selenium.WebElement'
at Search.search(Search.groovy:22)
at Search$search.call(Unknown Source)
at Main.main(Main.groovy:22)
請幫我解決錯誤
注:如果我啓用WebElement elementToClick = driver。$(「a」,title:「searchTerm」); elementToClick.click()這一行 它拋出錯誤$()方法返回null
將'WebElement'更改爲'def'。我懷疑你的問題是,與標題的鏈接並不在頁面上點擊 –
存在()方法得到錯誤:夾縫:groovy.lang.MissingMethodException:法無簽名:geb.navigator.NonEmptyNavigator.click()是(java.util.LinkedHashMap,java.lang.String)values:[[title:my account],a] 可能的解決方案:click(),click .util.List),wait(),last(),size() – abi
EmptyNavigator是不是表示該元素不存在? – blackdrag