我正在使用 selenium 中的代码示例,但不断收到错误“错误:无法找到或加载主类测试”。当我下载并解压 selenium 并在 Eclipse 中提取 jar 文件时,我不确定是什么原因造成的。我在适当的文件下也有“Test”类,我不确定是什么导致了这个问题。这是代码
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();
}
}
最佳答案
更新 Eclipse 中的运行配置。它应该指向示例类。
关于java - Selenium 代码示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27605462/