If you have missed the previous post then you can have a look at here .
Now we are ready to start our first script in Webdriver using Eclipse .Open your Eclipse and follow the below steps
1.Create new Java Project
2.Add the Webdriver Jar files to the created Project
3.Create a new Package under Java Project
4.Create a Java class file under the Package
5.Write the code in the Java class file and run it.
1. Create a new Java project
Goto File >> New >>Java Project
We will get a popup which will prompt us to provide the project name.
Give the project name say "ExploreWebDriver" then click on Finish button.
2.Add the Webdriver Jar files to the created Project
Right click on created project then goto
Build Path>>Configure Build Path >>Select Libraries tab>>Add External jars
Which will open a folder search prompt , goto the locations where you have downloaded WebDriver jar files and add them .Then click on "Ok" button
You need to add below jar files.If you don't have these files downloaded on your computer then you can download them from the below pages :
http://seleniumhq.org/download/
http://code.google.com/p/selenium/downloads/list
You can also download all jars from my shared location
https://docs.google.com/folder/d/0B00rtzEfza2uZnRBZnNVWHFVNjA/edit
3.Create a new Package under Java Project
Goto creatd project i.e. "ExploreWebDriver" and expand it.Now we will see a separate folder named "src". Right Click on it and then Goto
New>>Package>>Give the name of package in the "package creation" popup. Say "learning" is the name of the Package.Now click on finish button.
Copy the below code and paste it in the created Java class file.
Here is how your Eclipse project hierarchy looks like :
Now we are ready to start our first script in Webdriver using Eclipse .Open your Eclipse and follow the below steps
1.Create new Java Project
2.Add the Webdriver Jar files to the created Project
3.Create a new Package under Java Project
4.Create a Java class file under the Package
5.Write the code in the Java class file and run it.
1. Create a new Java project
Goto File >> New >>Java Project
We will get a popup which will prompt us to provide the project name.
Give the project name say "ExploreWebDriver" then click on Finish button.
2.Add the Webdriver Jar files to the created Project
Right click on created project then goto
Build Path>>Configure Build Path >>Select Libraries tab>>Add External jars
Which will open a folder search prompt , goto the locations where you have downloaded WebDriver jar files and add them .Then click on "Ok" button
You need to add below jar files.If you don't have these files downloaded on your computer then you can download them from the below pages :
http://seleniumhq.org/download/
http://code.google.com/p/selenium/downloads/list
You can also download all jars from my shared location
https://docs.google.com/folder/d/0B00rtzEfza2uZnRBZnNVWHFVNjA/edit
- a.selenium-java-2.32.0-srcs.jar
- b.selenium-java-2.32.0.jar
- c.selenium-server-standalone-2.32.0.jar
3.Create a new Package under Java Project
Goto creatd project i.e. "ExploreWebDriver" and expand it.Now we will see a separate folder named "src". Right Click on it and then Goto
New>>Package>>Give the name of package in the "package creation" popup. Say "learning" is the name of the Package.Now click on finish button.
4.Create a Java class file under the Package
Right click on the created package i.e "Learing" and then goto
New>>Class>>we will get "New Java Class" popup. Enter the name of the class say "GoogleSearch" and click on Finish.
5.Write the code in the Java class file and run it.
Copy the below code and paste it in the created Java class file.
package learning; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class GoogleSearch { public static void main(String args[]){ WebDriver driver=new FirefoxDriver(); System.out.println("Loading Google search page"); driver.get("http://google.com"); System.out.println("Google search page loaded fine"); } }
Here is how your Eclipse project hierarchy looks like :
Now Click run .
Script will run successfully and a new firefox window will be opened with the Google.com .
I want to open internet explorer not firefox browser...
ReplyDeleteIf u know plz tell me how?
Below post is for opening interner explorer. http://www.mythoughts.co.in/2012/05/starting-opera-browser-using.html
ReplyDeleteHi vamshi,
ReplyDeleteI am new on selenium. i am trying to implement your code, but i colud not open google page. i could not identify problem can you help me.
Thanks in advance
issue is resolved now, it's happens because of old version of jar files......:)
ReplyDelete:)
ReplyDeleteif i dont know java or any other lang. then can i record scripts using IDE and export them in eclipse in java/webdriver format??
ReplyDeleteSelenium IDE has its own limitations. In some cases export works fine but in most of the cases it may not work due to the limitations of Selenium IDE.
ReplyDeleteIt is good to have basic of java and guess what they are good enough to work :)
Greetings! I've been reading your weblog for some time now and finally got the
ReplyDeletebravery to go ahead and give you a shout out from Humble Tx!
Just wanted to say keep up the excellent job!
My web-site; Wholesale Snapbacks