我正在尝试按照https://code.google.com/p/selenium/wiki/GettingStarted上的示例进行操作,但是我遇到了包org.openqa.selenium.example“不正确”的问题.除了公共类之外,代码的其余部分似乎没问题.示例中还有一个红点说它需要声明,但我认为这是因为上面的包有问题.
当我运行代码时,这是输出:
Error: Could not find or load main class test.Test
/Users/me/Library/Caches/NetBeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)
我知道这里有一个类似的线程:Can’t run Java example for Selenium / WebDriver,但这是我第一次使用Java和Selenium,我仍然很难解决这个问题.如果您不想按照示例的链接,这是我的代码:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.openqa.selenium.example;
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();
}
}
编辑:
解决方法:
您的包含.java类的src包是错误的.它应该是org.openqa.selenium.example而不是示例.由于在类中声明的包与在外部声明的包不同.它引发了编译时错误.将包装重构到src包外部的org.openqa.selenium.example或编辑org.openqa.selenium.example以解决问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。