Biswajit440
Biswajit440

Reputation: 1

Unable to launch Firefox browser using selenium web driver

I am unable to launch Firefox browser using selenium webdriver 3.4.0

Browser version: Firefox 54.0.1

This is my code:

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", "C:\\xx\\geckodriver.exe");
     WebDriver driver=new FirefoxDriver();
    driver.get("http://www.google.co.in");
    driver.quit();
 }
}

Getting Error

1508548441651 geckodriver INFO geckodriver 0.18.0 1508548441660 geckodriver INFO Listening on 127.0.0.1:48046 Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:48046 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'ADMINRG-627BJ6K', ip: '192.168.1.3', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131' Driver info: driver.version: FirefoxDriver at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:91) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:137) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:191) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:104) at com.webdriver.Testing.main(Testing.java:15) Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:48046 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:139) at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:87) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:343) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:159) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) ... 8 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ... 23 more

Upvotes: 0

Views: 2439

Answers (3)

khushal sharma
khushal sharma

Reputation: 71

In case of some firefox browser version, driver is not able to launch browser using property "webdriver.gecko.driver". Instead of this you can try following code:

 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    WebDriver driver = new FirefoxDriver(capabilities);

Upvotes: 2

Vinay
Vinay

Reputation: 33

Instead of using driver of specific browser, you can use "Webdrivermanager" plugin in maven, so it will resolve most of problems related to browser and its instance. Even this help me lot to overcome browser related problems. E.g. 1. Add Webdrivermanager plugin with maven 2. Directly call browser of your choice like firefox as mentioned below.

FirefoxDriverManager.getInstance().setup(); driver= new FirefoxDriver();

Upvotes: 2

Jain Devassy
Jain Devassy

Reputation: 41

Try this way: I am using C#, but this way worked for me. You can follow same way of doing in Java Provide 'firefox.exe' & 'GeckoDriver' as your local path

var binary = new FirefoxBinary(@"----Firefox.exe Path------");
var profile = new FirefoxProfile();
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(@"----GeckoDriver Path------");
service.FirefoxBinaryPath = @"----Firefox.exe Path------";
driverInstance = new FirefoxDriver(service);

Upvotes: 0

Related Questions