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?

1

2 Answers 2

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'.

Sign up to request clarification or add additional context in comments.

Comments

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")}

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.