How to Get a Selenium/Ruby Bot to Wait Before Performing an Action

Load all elements on page Selenium + Ruby

Instead of this

driver.find_elements(:xpath => "//p").each do |r|
puts "Cell Value: " + r.text

Please try this

driver.find_elements(:xpath => "//p").each do |r|
puts "Cell Value: " + driver.execute_script("return arguments[0].innerHTML", r)

Please let me know if this work for you.

Using Nokogiri and Selenium, is it possible to skip a command if the driver is unable to perform it?

Following @max pleaner advice, you could rescue the exception about not finding the element and then do something with that information. The exception you are looking for in this case is NoSuchElementError.

The code could look like this:

User.all.each do |u|
driver.navigate.to "http://website.com/" + u.name
begin
driver.find_element(:class, "like").click #THIS IS THE LINE THAT SOMETIMES FAILS
rescue Selenium::WebDriver::Error::NoSuchElementError
u.error = true
u.save
end
end

Wait for an iframe to open and load with Selenium

Not sure if this will work because Iframes run in a separate sandbox to normal frames because you can do cross site page calls and they may have their own JavaScript which you wont be able to interact with.

@selenium.wait_for_frame_to_load "iframe", "30000"

it may work if you run your tests in *chrome or *iehta but don't have anything at the moment to test with

selenium-webdriver and wait for page to load

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'

How to wait for a page redirect in Selenium?

Monitoring the value, returned driver.get_location did the job perfectly to me.
Apparently, from what I've understood in my 5 mins peeping into the code was that window.location.href value is monitored under the hood.



Related Topics



Leave a reply



Submit