Link to home
Start Free TrialLog in
Avatar of VapiSoft
VapiSoft

asked on

Getting Stated with Java

Hi,
I am getting-stated with Java because I want to use Selenium 2 in Java.
I have an experience with Elipse IDE for PHP and for JavaScript.
I oped a new Java Project.
and the src folder I added anew Java File and copied the GettingStated Selenium file to is (as my first Java application).
Now I want to run it.
I added the file as the main class to the "Run Configuration"  and Run it (Apply).
I received and error:  Could not find the main class: src/GettingStated.js.  Program will exit.
 User generated image
SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VapiSoft
VapiSoft

ASKER

Thanks.
The second link is very helpful.
I am sorry, but after I followed the examples, I still cannot compile/run the Selenuim 'Getting Started' that I downloaded.
It comes with two jar files:
selenium-java-2.0b3.jar
selenium-java-2.0b3-srcs.jar
and a lib folder with many jar files.
I imported the jar files (from another folder to my folder)
But when I tried to add it to my space, I get a lot of X (almost every line) - see the attached picture
package org.openqa.selenium.example;

	import org.openqa.selenium.By;
	import org.openqa.selenium.WebDriver;
	import org.openqa.selenium.WebElement;
	import org.openqa.selenium.firefox.FirefoxDriver;

	public class MyFirstClass {
	    public static void main(String[] args) {
	        // Create a new instance of the Firefox driver
	        // Notice that the remainder of the code relies on the interface, 
	        // not the implementation.
	        WebDriver driver = new FirefoxDriver();

	        // 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());
	        
	        //Close the browser
	        driver.quit();
	    }
	}

Open in new window

ScreenShot-4863.jpg
You need to add all the jars to your classpath. Classpath is kind of like the Windows PATH variable to Java -- it defines the locations and jar files where other classes needed by your class can be found.

I'm working from memory at the moment but I think you need to right click on the project, select Properties, find Build Path in the project properties tree (maybe under Java?) and then there should be a tab where you can add the jars to your classpath.
Thanks jim,

I added all the jars to the java build path (see picture), but I still have the same errors.
 User generated image