Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Created July 9, 2017 09:04
Show Gist options
  • Select an option

  • Save prashanth-sams/e35b9cb65907d2bc7faa0eed926ec50e to your computer and use it in GitHub Desktop.

Select an option

Save prashanth-sams/e35b9cb65907d2bc7faa0eed926ec50e to your computer and use it in GitHub Desktop.
generic selenium methods
def wait_for_ajax(timeout = 60, message = nil)
wait_for_jquery(timeout / 2, message)
super(timeout / 2, message)
end
def wait_for_jquery(timeout = 30, message = nil)
end_time = ::Time.now + timeout
until ::Time.now > end_time
begin
return if @browser.execute_script('return jQuery ? 1 : 0;') == 1
puts 'jQuery not yet loaded, waiting half a second...'
rescue Selenium::WebDriver::Error::UnknownError => jquery_error
puts "jQuery not yet loaded, or failed when checking if it loaded: #{jquery_error}\nWaiting half a second..."
end
sleep 0.5
end
message = 'Timed out waiting for jquery to load' unless message
raise message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment