Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium-webdriver and wait for page to load

I'm trying to write simple test. My problem is, that i want to wait until the page is loaded completly. At the moment i'm waiting until some elements are presen, but that is not really what i want. Is it possible to make something like this:

driver = Selenium::WebDriver.for :chrome
driver.navigate.to url
driver.wait_for_page_to_load "30000"

With Java isn't problem, but how to make it with ruby?

like image 619
cupakob Avatar asked Jul 07 '12 07:07

cupakob


1 Answers

This is how the Selenium docs () suggest:

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get "http://google.com"

element = driver.find_element :name => "q"
element.send_keys "Cheese!"
element.submit

puts "Page title is #{driver.title}"

wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { driver.title.downcase.start_with? "cheese!" }

puts "Page title is #{driver.title}"
driver.quit

If that is not an option you can try the suggestion from this SO post though it would require some Javascript on top of the Ruby/Rails.

It seems that wait.until is being/has been phased out. The new suggested process it to look for the page to have an element you know will be there:

expect(page).to have_selector '#main_div_id'
like image 85
ScottJShea Avatar answered Sep 17 '22 21:09

ScottJShea