Home
Archive for
2016
How to use Firefox in Selenium using geckodriver in Selenium 3
Good news for Selenium users, Recently Selenium has launched Selenium 3 with so many new changes.In this post I will show you how to use Firefox in Selenium using geckodriver which will run the test.
If you are using Selenium 3 then to work with Firefox browser you need to use separate a driver which will interact with Firefox browser. If you have noticed then we have done the same thing for Chrome and IE browser as well.
One important thing in this post is even if you are using Firefox beta version then it will work. If you are using firefox 47 and so on then it will work.
webdriver.chrome.driver for Chrome browser
webdriver.ie.driver for IE browser
Now we have to use webdriver.gecko.driver for Firefox as well
Note- if you are still using Selenium 2 like 2.53 and 2.51 or any version then you don’t have to set this path.
Let’s run a basic program with Selenium 3 beta version
Program 1 without any driver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test1 {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.quit();
}
}
|
Output console
The path to the driver executable must be set by the webdriver.gecko.driver system property;
Firefox in Selenium using geckodriver
As you can see to work with Firefox we have to set the property now. You can download the driver from Github and then you can extract and you will get .exe file.
Download URL – https://github.com/mozilla/geckodriver/releases/tag/v0.9.0
Complete program for Firefox in Selenium using geckodriver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test1 {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","G:\\Selenium\\Firefox driver\\geckodriver.exe");
// if above property is not working or not opening the application in browser then try below property
//System.setProperty("webdriver.gecko.driver","G:\\Selenium\\Firefox driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
System.out.println("Application title is ============="+driver.getTitle());
driver.quit();
}
}
|
Now you can run the program and you will get expected output.
Subscribe to:
Posts
(
Atom
)