2014-09-23 206 views
-1

我是Selenium的新手,只是試圖用它打開瀏覽器,但這給我一段艱難的時間。每當我嘗試運行下面的代碼,它給了我這個錯誤:嘗試使用Selenium運行簡單腳本時發生錯誤

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Syntax error on token "void", @ expected 
Syntax error on token "]", :: expected after this token 
Syntax error, insert "enum Identifier" to complete EnumHeader 
Syntax error, insert "}" to complete EnumBody 

at TestClass1.main(TestClass1.java:7) 

我已經嘗試了很多東西,但找不到任何東西。

public class TestClass1{ 

    import org.openqa.selenium.WebDriver; 
    import org.openqa.selenium.firefox.FirefoxDriver; 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 
     //System.setProperty("webdriver.firefox.bin", "c:\\path\\to\\firefox.exe"); 

     WebDriver driver = new FirefoxDriver(); 
     driver.get("www.google.com"); 
     driver.quit(); 
    }} 

} 
+0

爲什麼你對你的類體的進口? – hexafraction 2014-09-23 15:30:59

+0

當你說你嘗試了很多東西時 - 當你搜索到你遇到的錯誤時,你發現了什麼? – anotherdave 2014-09-23 15:36:31

+0

嗨Hexafraction謝謝你的幫助,它爲我工作。 – 2014-09-25 07:01:36

回答

1

將您的類的外部導入,並嘗試使用http://你的網址 -

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class TestClass1{ 

    public static void main(String[] args) { 

    WebDriver driver = new FirefoxDriver(); 
    driver.get("http://www.google.com"); 
    driver.quit(); 
    } 
} 
相關問題