我正在关注selenium中的代码示例并且我一直收到错误"错误:无法找到或加载主类Test。"当我下载并解压缩selenium并在Eclipse中解压缩jar文件时,我不确定是什么导致了这一点。我也有班级"测试"在适当的文件下,我不知道是什么导致了这个问题。这是代码
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example {
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
答案 0 :(得分:0)
在Eclipse中更新您的运行配置。它应该指向Example类。