Hi Guys, I think you must be happy that you have completed your Selenium Webdriver Installation and now you are ready to execute selenium test on firefox browser.
If you are new to Selenium and still have not completed installation part then no worry at all. Check below article which will help you with that- Install Selenium Webdriver in Windows Machine
If Selenium 3 is getting used then must visit Selenium Firefox with GeckoDriver.
How to use Firefox in Selenium using geckodriver in Selenium 4
Before going to write our first Selenium Script, I would like to introduce some of the articles which will help you in the long run.Since you are new to Eclipse I will suggest you that you should know some of Eclipse Tips and Tricks.
Since we are going to use multiple browser and XPath very frequently throughout our learning process so you should have some plugin installed in your browser which generates XPath.
I found this awesome plugin which will generate multiple xpath even for Single Element, but the limitation of this plugin is that it works only with firefox.
Xpath plugin for Firefox browser.
For another browser may be we have to wait but still in Chrome you will find one plugin which will detect the element based on xpath.
Xpath Checker for Chrome Browser
Now I think I have given so many different links which might confuse you so let’s get Started with first Selenium Webdriver.
I have created a video long back which will help you while designing Selenium Script so I will highly recommend you to watch this video.
It will hardly take 15 min but will give you clear picture that How we will be working once we move forward.
First Selenium Webdriver Script in Firefox
Now it is time to start Selenium webdriver scripting, till now we have downloaded all the required jars and plugin.
1-Open eclipse and create a new Java project as of now but once we will move forward we will be using Maven project which will give advance level functionality.
If you want to give a try now itself it would be very good because in future we are going to use Maven project only.
If You are working with Selenium 3 then this post is MUST
Below article will help you to work with maven and later on we will be integrating this withJenkins.
2- Create Maven project and get Started.
But if you are getting confused now then take a deep breath and continue with below article 🙂
Here you will get project also but you can directly select Java project.
2- Enter project name depends on your requirement
3- Now you will get library section where you have to add jars, which we downloaded, earlier simply click on add external jars option
4- New window will open, browse your location and add all jars which we downloaded.
Note- If you add selenium-server-standalone- 2.X.X only then also you can write automation script
5-Now click on finish button
Now you can see your project listed in Project explorer
Execute selenium test on firefox browser
Step 1- Since we are working with Java so we need to create Java class.
Step 2- Please specify package name (lower case) and specify the class name and click on Finish button.
Note- you can check the public static void main checkbox so we can directly write webdriver script.
Step 3- Here will use WebDriver Interface and FireFoxDriver class
Note 1 :- WebDriver is an Interface(interface have only function prototype) in which by default all the method (public ,static)has to declare d.
2:- WebDriver handles all activity which is related to Browser.
Note 2: FireFoxDriver is a Class who has implemented all the method of WebDriver Interface.
Note- Eclipse comes with very good option that is same like google autosuggestion, if you use some keywords in Eclipse, it will show you the related keywords matches
Setup you shortcut preferences
1- Click on Window and Click on Preferences option
2- General > keys> Search Content Assist> Bind your keys (in my case I set up Ctrl+Alt+Space by pressing respective key)> Click on Apply.
Type WebDriver and Press(Al+Ctrl+Space) so this will give you all the classes and interface which have WebDriver, so select WebDriver (Interface) and create a reference.
Step 4- Create webdriver reference
WebDriver driver=new FirefoxDriver();
Above code will initialize the firefox browser
Open any webpage for this we will use get methods which will accept url in String form followed by http:
Note- If you don’t provide http: in your application URL you will get some exceptions as well
Note:- Eclipse has this feature by default if you use Eclipse autosuggestion it will import all the necessary packages.
1- To run the Program,
Right click on program and Run-As- Java-Application
Now you will notice that Firefox will start and it will launch the application. If not then no worry drop a message below and I will help you.
Since we are done now it party time and now you can take rest.
But this is just a start so once you are done with party come back and let’s start with some topic.
Till now we have worked with Firefox but what about other browsers. In Automation you should make sure your Automation Script should run in all browser so now I have a task for you.
Assignment for you- Run the same application with other browsers too like Chrome, IE, Opera, Safari and so on.
I have worked with Firefox, Chrome and IE only and I think that enough for most of the application.
I have written two more article which will help you to start with other browsers too.
This article will help you to launch for application in Chrome browser
Launch First Selenium Script in Chrome Browser
Once you are done with Chrome then stretch a little bit and try to run the same application in IE browser.
I don’t want to demotivate you but It is my responsibility here to tell you the facts about IE. Since IE browser is very much concerned about security you will find a couple of Issues with IE browser but again no worry I have created a detailed article on it and very good news that you will face this question in Interviews as well.
Check below article which will help you to understand IE issues with Selenium.
Challenges with IE Browser while working with Selenium
Now you are familiar with IE issues and you must be ready now so without wasting much time let us start with IE Browser.
Launch First Selenium Script in IE Browser
Now you are done with all browser so now you must be having little bit confidence in Selenium so sit back relax.
Once you move forward you have to perform Cross Browser Testing as well but I will recommend then please don’t try this now because it includes so many high-level concepts like testng.xml.
But if you still want to see how it works then I would be happier.
Now its time to close this post and let’s move forward to another one. Since I have many topics in this post so you will definitely have some doubts so your doubts are always welcome.
If you really think this article will help others too then please share this with others too.
For More updates Learn Automation page
For any query join Selenium group- Selenium Group
DK says
http://learn-automation.com/eclipse-tips-and-tricks/
This link is broken
Mukesh Otwani says
Hi DK,
It is working now
sid says
hii i have a query…When I Type WebDriver and Press(Al+Ctrl+Space) its not showing all the classes and interface which have WebDriver…
Mukesh Otwani says
Type Control and Space only.
Paarul says
Same error
Mukesh Otwani says
Hi Parul,
Please add selenium server standalone jar to fix the issue.
Rakhi Sharma says
Hi Sir,
I am facing issue related to firefox browser. Please find the error below: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Mukesh Otwani says
Hi Rakhi,
You need to use Gecko driver to fix the issue.
Kindly go through below post and video to solve this issue.
http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
Bharath B says
hi Mukesh
when i run the above class for the second time i am getting the below error, can u please help he how to debug this.
Selenium webdriver version : 3.0.1
FF version 46.
i tried with FF latest version too, and still facing the same issue.
Exception in thread “main” org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_91’
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.SocketLock.lock(SocketLock.java:71)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:68)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:163)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:80)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:141)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:97)
at tutor.MyClass.main(MyClass.java:12)
Mukesh Otwani says
Hi Bharath,
You have to use Gecko Driver as well in order to work with Firefox browser with Selenium 3.
Below link will guide you for the same.
http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
Phani says
Hi, how to add javadoc in the project for selenium 3.0.1
Mukesh Otwani says
Hi Phani,
You can download src code and then attach in project.
Rachit Goyal says
Hello sir, Firefox is started but the url which i paste in the code was not open , please help me out of this
Mukesh Otwani says
Hi Rachit,
Kindly follow updated doc http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/
sudhr says
how many test case can we written in a single java class
Mukesh Otwani says
You can have n number of test 🙂 We dont have any limitation as such.
kishore says
hii Mukesh ,
really awesome explanation.I applause your great concern about selenium.
Mukesh Otwani says
Thank you so much Kishore. Keep in touch and let me know if any help required in Selenium.
Kajal says
Hello Mukesh,
Thanks for sharing. Your tutorials are very helpful.
Actually I have one query, I’m trying to open mozilla firefox(49.0.1) using selenium 2.48, It shows default page of the firefox instead of loading the page for which I have passed URL while writing script. also it doesn’t show any error message. what will be the solution for this? please help..!
Mukesh Otwani says
Hi Kajal,
Here is the solution http://learn-automation.com/use-firefox-selenium-using-geckodriver-selenium-3/ and Kindly check the video too.
anusha says
Hi Mukesh,
Your blog is very helpful and thanks a lot for sharing..!! 🙂
I would like to know how to handle menu items (eg : books & more in flipkart.com so that i can navigate to options inside it)
Basically how to handle
Thanks
Anusha
Mukesh Otwani says
Hi Anusha,
Below video will help.
Use List of WebElements to get all link from flipkart
Balaji says
Hi
mukesh this is Balaji iam big fan of you bcz i learn completly by following your youtube videos and learn automation site now i got job in ibm thank you so much
Mukesh Otwani says
Hey Bala,
First of all congratulations for new Job 🙂 and really your comment made my day. Keep visiting and let us know if any help required from our end.
sudhr says
What if we dont have locators information.Is there any method to automate
Mukesh Otwani says
Sorry did not understand your question 🙁
sudhr says
What if we dont have locators for webelements.Is there any methods to automate the webpage?
got this Question from an interview?
Mukesh Otwani says
You can use tag name and then findElementS using tagname.
sudhr says
“8 . assume there are 50 names every name has a link called edit how will you click on the your name
if it is present some where in the 39 the row ??
”
9. if it is present some where in the 39 the row ??
Mukesh Otwani says
Hey Sudhr,
Use dynamic xpath in this case. Kindly check dynamic xpath post.
Sandip Parbatrao says
Hi Mukesh,
I went through the videos and those are very helpful. Thanks for creating and sharing it.
Mukesh Otwani says
Thank you so much Sandip
sandip says
Mukesh I have gone to your videos on YouTUbe , All are great,well explained.
Now started looking into each chapter from today
Mukesh Otwani says
Hi Sandip,
Thanks a ton. Please share with your friends as well.