2

I am writing a program in Selenium using Java. In my code, I have:

driver = new FirefoxDriver();

My problem is this: if I am not connected to the internet when the program executes this line of code, the program will hang for a long time (on the order of minutes) before finally opening up a Firefox Window and then crashing on the next line of code

driver.doWhatever();

I am trying to make this as user friendly as possible, so I would love to have my program exit if

driver = new FirefoxDriver();

does not complete within fifteen to twenty seconds.

Is there a way to do this in Java? I could always go into Selenium and tinker with it so that it works the way I want it to, but that seems like the "wrong" way to go about solving this problem.

Thanks in advance.

cobrabb
  • 141
  • 2
  • 10
  • Try Downgrading Firefox (or upgrading Selenium) Dup http://stackoverflow.com/questions/10715576/selenium-hangs-instantiating-firefoxdriver? – lreeder Aug 29 '13 at 17:21
  • I could try this, but Selenium seems to be working normally 99% of the time. It is only when I am not connected to the internet that it hangs, and then only for a while. To me, it seems like "hanging while offline" is perfectly normal behavior, I'm just looking for a way to change that behavior. – cobrabb Aug 29 '13 at 17:25

1 Answers1

4

The driver class may be modified to adjust the wait time that you are having trouble with.

It should look something like this:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

You could adjust the time to whatever you want, but be warned that reducing it too low may cause other issues, for example if the page is simply taking a little longer to load, it will timeout prematurely.

Source: WebDriver: Advanced Usage -- Selenium Documentation

Stephen B.
  • 204
  • 2
  • 9
  • Great! This is exactly the type of thing I was looking for. It solves my problem and does not require actually messing with the Selenium source. I figured that there was a solution for me out there somewhere. – cobrabb Aug 29 '13 at 18:45