Problems with explicit wait and implicit wait in Selenium Webdriver (Selenium 2) using Python

I need to work with some really slow proxies and get stuck from time to time. So I'm trying to find a solution / workaround for this, here is my problem:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

browser = webdriver.Firefox()
browser.get("http://whateversite.com")

element = browser.find_element_by_id("element")
element.click() # go to page http://whateversite.com/page.html

new_element = browser.find_element_by_id("newElement")

Regardless of whether you set up in browser.implicitly_wait(30)front of the hand or use new_element = WebDriverWait(browser, 30).until๏ผˆlambda browser : browser.find_element_by_id("newElement"))it, it just got stuck, sometimes for CLOCK. It seems to wait for this page to http://whateversite.com/page.htmlbe fully loaded, which in some extreme cases can take several hours.

What should I do to avoid this?

+5
source share
2 answers

. FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("webdriver.load.strategy", "unstable"); WebDriver driver = new FirefoxDriver(profile); ` http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#current-document-readiness

. driver.manage(). timeouts(). pageLoadTimeout (30, TimeUnit.SECONDS); http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#pageLoadTimeout%28long,%20java.util.concurrent.TimeUnit%29

0

, , . , -, , . expect - tcl, - - . sel , python sleep :

def wait(waittime=30):
  print 'kick'
  time.sleep(waittime)

..

run.exp:

set timeout 30
set try 0

while 1 {
    spawn /usr/bin/python test.py
        while 1 {
            expect "kick" {exp_continue}
            timeout {
                if {$try > 5} {
                    exit
                }
                incr try
            }
        }
    }
}

, , , . 5 . , ..

0

All Articles