3

This question is some thing different.
In my program i have more than 9 expected assertions.So, i have to reduce the wait time time if an element is not found.

for i in range(len(10)):
    try:
        i.click()
        driver.find_element_by_name("XXX").send_keys("XXXX")
    except Exception,e:
        print "this is an expected assertion so as to continue the program further iteration"

In the above program due to the Unable to find element assertion it taking a lot of time..
How can i reduce the wait time...

  • I don't want to set the default time... I want to decrease the default time – Mahesh Reddy Atla Dec 17 '13 at 08:35
  • 1
    Then use the command to set the default time, to a lower value. That's all you'd need to do. – Mark Rowlands Dec 17 '13 at 09:11
  • Why do you want to have such an effect? If you can find them there are mostly two reasons: you are looking for the wrong element or you can't find the element because you haven't retrieved them so far. – Jon Dec 17 '13 at 09:17
  • @Jon I need to iterate the steps which is mandatory and i know there is no element in those iterations except in one case – Mahesh Reddy Atla Dec 17 '13 at 12:09

1 Answers1

0

add import selenium.webdriver.support.ui as ui to your header.

the WebDriverWait object will wait until it find what you want :

try:
    timeout = 10
    wait = ui.WebDriverWait(driver, timeout)
    wait.until(
        lambda driver : driver.find_element_by_name("XXX").send_keys("XXXX")
    )
except TimeoutException:
    # timeout

edit :

WebDriver has a default of 60 sec internal timeout (it's the ruby doc, but it should be the same for python) :

Internally, WebDriver uses HTTP to communicate with a lot of the drivers (the JsonWireProtocol). By default, Net::HTTP from Ruby's standard library is used, which has a default timeout of 60 seconds. If you call Driver#get on a page that takes more than 60 seconds to load, you'll see a TimeoutError raised from Net::HTTP.

Try to reset the timeout like that :

driver.set_page_load_timeout(0)
driver.set_script_timeout(0)

doc : set_page_load_timeout, set_script_timeout

onionpsy
  • 1,502
  • 11
  • 15