Selenium determine browser is frozen

后端 未结 2 1128
不思量自难忘°
不思量自难忘° 2021-01-23 15:21

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 th

相关标签:
2条回答
  • 2021-01-23 16:02

    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
    
    0 讨论(0)
  • 2021-01-23 16:06

    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

    0 讨论(0)
提交回复
热议问题