2

I am using Selenium for automation (C#, selenium 3.3.4, gecko driver 0.16.0, on Win 7 64 Bit, driven by Powershell)

I have set the Firefox profile to automatically download files to a specific folder:

$profile.SetPreference("browser.download.dir", $downloadPath)
$profile.setPreference("browser.download.folderList", 2);
$profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/csv,application/octet-stream,text/plain");

When I set the browser URL to the download link, the download happens immediately, but then the script stalls for almost exactly one minute every time afterwards. The URL in the address bar stays the same, I suspect that this causes the wait in the first place (a wait for the page to load).

When opening the next URL after the 1 minute wait the delay is not over though. Then a few of the 1 minute cycles seem to be necessary before the browser accepts the new url and opens it. It seems like hitting the first timeout causes things to go awry.

I have tried setting the implicit wait to 20 seconds, but that didn't seem to have an effect and I have thus removed it again. How to make all this go more smoothly?

Here is my attempt at setting the implicit wait:

$timespan = [System.TimeSpan]::FromSeconds(20)
$firefox.manage().timeouts().implicitlyWait($timespan) | out-null
1

Don't use implicit wait - only explicit. And read up explicit wait for expected conditions, like presence/absence of element located by ID or name or CSS (avoid XPath).

  • If I don't explicitly set the implicit wait, is it still active? And XPath is somehow buggy? Only for waits? It's my main selection method – Sandro May 6 '17 at 16:30
  • Implicit is still active, but different parts of selenium command chain (server, grid, webdriver) might have different value than your code has. Using explicit wait, there will be no misunderstandings. XPath is flaky (does not work reliably - see all those questions being asked about XPath not working) and might break after trivial design changes. – Peter M. May 8 '17 at 14:51
  • 1
    Thinking about it, my XPath usually went after CSS properties anyway, namely the class attribute. I haven't started the conversion, yet, but the following seems to be a good resource for such an overhaul. saucelabs.com/resources/articles/selenium-tips-css-selectors Thanks Peter – Sandro May 9 '17 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.