【发布时间】:2013-11-22 11:56:48
【问题描述】:
我已经安装了 jdk6 (jdk1.6.0_26) 和 jdk7 (jdk1.7.0_25)。我有以下两个 java 类:
第一个 java 文件:
package code.google.com.p.selenium;
import org.openqa.selenium.WebElement;
public class GoogleSearchPage {
// Here's the element
private WebElement q;
public void searchFor(String text) {
// And here we use it. Note that it looks like we've
// not properly instantiated it yet....
q.sendKeys(text);
q.submit();
}
}
第二个java文件:
package code.google.com.p.selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.PageFactory;
public class UsingGoogleSearchPage {
public static void main(String[] args) {
// Create a new instance of a driver
WebDriver driver = new HtmlUnitDriver();
// Navigate to the right place
driver.get("http://www.google.com/");
// Create a new instance of the search page class
// and initialise any WebElement fields in it.
GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);
// And now do the search.
page.searchFor("Cheese");
}
}
我正在使用 Eclipse Indigo。在eclipse中,我做了以下步骤:
- 右键单击 UsingGoogleSearchPage.java
- 点击运行方式->Java应用程序
程序未执行。发生错误(请参见图片)。
【问题讨论】:
标签: java eclipse selenium jvm selenium-webdriver