I have installed both jdk6 (jdk1.6.0_26) and jdk7 (jdk1.7.0_25). I have two following java classes:
1st java file:
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();
}
}
2nd java file:
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");
}
}
I am using Eclipse Indigo. In eclipse, I did the following steps:
- Right click on UsingGoogleSearchPage.java
- Click Run As->Java Application
The program was not executed. An error was occurred (Please see the image).
