1

I'm using selenium to do some stuff that involves loading quite a number of pages, potentially with numerous images and/or flash ads, which is apparently rather stressful on the browsers, since my firefox browsers are freezing. Is selenium capable of detecting if a browser is frozen, as in has reached that horrid state of "not responding" in the task manager and won't focus if i click on the tab? If not, does anybody know of a way to deal with that case?

EDIT:

I ended up using the following:

  browser = webdriver.Firefox()
  try:
    browser.set_page_load_timeout(_DEFAULT_LOAD_TIME)
    browser.get('http://' + domain)
  except TimeoutException as te:
    print "Loading %s timed out. Killing browser." % domain
    print te
    browser.close()

Although it does not close the browser if it gets into a (not responding) state, but with a low enough _DEFAULT_LOAD_TIME, it usually manages to kill the browser before it gets into that state.

Jainathan Leung
  • 1,147
  • 2
  • 15
  • 27
  • I doubt Selenium will do anything for you, but you should be able to interface with the OS to track what processes you opened, then monitor and manage them. http://stackoverflow.com/questions/1632234/python-list-running-processes-64bit-windows Of course, you could also see if you could optimize your tests in such a way that you don't need to have all the pages open concurrently... – Silas Ray Jan 25 '13 at 18:33

2 Answers2

2

At least you can set a timeout for Selenium. In the following example the webdriver will wait at most 10 seconds before killing the browser and failing the test. This way you can get all the tests executed eventually.

from selenium import webdriver

ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds
ff.get("http://somedomain/url_that_delays_loading")
myDynamicElement = ff.find_element_by_id("myDynamicElement")

See more information at Selenium headquarters

Edu
  • 2,017
  • 17
  • 23
0

The best strategy I came up with was to just terminate processes that have been running longer than a set threshold (e.g. orphaned processes). This snippet can be called via child_process.execFile('powershell.exe'). Found this useful for chromedriver and webdriverJS when the browser hangs because of misbehaving javascript.

Cleanup Orphaned Processes (Runtime >30 min)

# View Processes Running > 30 MIN
Get-Process -name firefox | ? { $_.StartTime -lt (Get-Date).AddMinutes(-30) } | select pid, starttime | Sort-Object starttime

# Terminate Processes Running > 30 MIN
Get-Process -name firefox | ? { $_.StartTime -lt (Get-Date).AddMinutes(-30) } | Stop-Process -Force
Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173