0

I'd like to wait until DOM is stable and the page is contructed until I try to execute Selenium WebDriver click() method.

Since Selenium 2 there doesn't seem to exist stock wait_for() method anymore. What's the best practice for "wait 15 seconds or until the element is clickable" style behavior with Selenium and Python 2?

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • related http://stackoverflow.com/questions/9823272/python-selenium-waiting-for-frame-element-lookups – jfs Jun 01 '12 at 15:52

2 Answers2

2

What you are looking for is is explicitly waiting. The Selenium documentation explains this further how explicit waiting works.

You can find different types of expected conditions here. The condition which probably interests you the most is the one called 'visibility_of'.

Jonathan
  • 8,453
  • 9
  • 51
  • 74
1

This is in ruby, i am sure it can be done in Python as well

@wait = Selenium::WebDriver::Wait.new(:timeout => 30)
#You can define as many as you want with various times
@wait_less = Selenium::WebDriver::Wait.new(:timeout => 15)
#and then
@wait.until { @driver.find_element(:id, "Submit") }
@driver.find_element(:id, "Submit").click

Note - You could wait for anything. other examples

@wait.until {@driver.window_handles.size > 1}

or

@wait_less.until {@driver.find_element(:tag_name => "body").text.include?("Some text")}
Amey
  • 8,470
  • 9
  • 44
  • 63
  • Thanks. This got me on the right track: http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_support/selenium.webdriver.support.wait.html#module-selenium.webdriver.support.wait – Mikko Ohtamaa Jun 01 '12 at 17:33