2014-09-23 208 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(); 
    } 
} 
相关问题