java - Selenium 代码示例不起作用

标签 java eclipse selenium

我正在使用 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/

相关文章:

javascript - 无法使用javascript从网址获取文本数据

java - Spring数据休息+Spring安全: @Secured not working

java 1.8.0_192 的 JavaFX 日志记录

python-3.x - Selenium webdriver python 元素屏幕截图无法正常工作

java - IProxyService.setProxyData 影响系统属性

在虚拟环境中用pip安装的Python包在eclipse中不起作用

java - 如何配置 Jenkins 运行 1 个 selenium 测试用例

java - BitmapFactory.decodeByteArray() 返回 NULL

java - 电子表格中没有 RuleTable 单元格 - Excel 文件和 DRT

java - 为 Tomcat 配置 SSL 连接器,由 eclipse 调用