1

I am using the below code to create a firefox web driver using Selenium Java API.But it neither create firefox instance nor gives any error message.Control comes directly to finally block after some time.

Java APi used - 2.46.0 Firefox version - 32.0.1 JRE -1.8.25

Can some one help me to debug the issue?

code -

WebDriver driver;
try{
 ProfilesIni profile = new ProfilesIni(); //ignore ietab+options
 FirefoxProfile defualtProfile = profile.getProfile("default");
 //defualtProfile.setAcceptUntrustedCertificates(false);

 DesiredCapabilities capabilities = DesiredCapabilities.firefox(); //To over come ssl certificate error
 capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
 capabilities.setCapability(FirefoxDriver.PROFILE,defualtProfile);                       
 Thread.sleep((long)(2000*Math.random()));
 driver=new FirefoxDriver(capabilities);

 return driver;
}
catch(Exception ex)
{   
        logger.error("Exception - > " + ex.toString());         
        return null;
}
finally
{
        logger.info("End");         
}
Sanjay Bhimani
  • 1,593
  • 1
  • 15
  • 29
Sona Shetty
  • 997
  • 3
  • 18
  • 41

1 Answers1

0

There is simple code to initialize firefox driver. Try below code and let me know. For more information refer this.

DesiredCapabilities dc=DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, profile);
Webdriver driver =  new FirefoxDriver(dc);
return driver;
Sanjay Bhimani
  • 1,593
  • 1
  • 15
  • 29
  • Issue is not with the code which i am using.Code i shared earlier is working fine in my local desktop.I suspect its an environment issue.I need the help of experts to unearth the issue. – Sona Shetty Jan 27 '16 at 07:10
  • It's not going to exception block...Control directly goes to finally block. – Sona Shetty Jan 27 '16 at 07:18
  • Hello Sona, I run your code and it is working properly. Driver is creating successfully. Other thing finally block is executed however the flow leaves the try block - whether by reaching the end, returning, or throwing an exception. In my case i am able to successfully open firefox using firefox driver. Your finally is executing because finally always executes. for more info please refer http://stackoverflow.com/questions/65035/does-finally-always-execute-in-java – Sanjay Bhimani Jan 27 '16 at 07:22
  • you mentioned it is not creating firefox instance and not giving error messages, and flow goes directly to finally block right? just try to explain me on which line your code is not working properly. – Sanjay Bhimani Jan 27 '16 at 07:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101747/discussion-between-sanjay-bhimani-and-sona-shetty). – Sanjay Bhimani Jan 27 '16 at 07:36