Reputation: 83328
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?
Upvotes: 0
Views: 1705
Reputation: 8891
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'.
Upvotes: 2
Reputation: 8548
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")}
Upvotes: 1