我是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 :(得分: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();
}
}