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
How to Count Existing Instances of a Class in Ruby
How Can Bundler/Gemfile Be Configured to Use Different Gem Sources During Development
How to Create Dynamic CSS in Rails
All Possible Combinations of Selected Character Substitution in a String in Ruby
Keyword Arguments Unpacking (Splat) in Ruby
Eliminate Consecutive Duplicates of List Elements
In Ruby, Why Is a Method Invocation Not Able to Be Treated as a Unit When "Do" and "End" Is Used
Interested in What the "<<" Does
Ruby Indented Multiline Strings
Ruby: How to Find the Key of the Largest Value in a Hash
Skip/Disable Force_Ssl for Particular Controller in Rails
Time Gt Query Not Working with Mongoid and Ruby on Rails
Why Is This Not a Syntax Error
How Does Activerecord Define Methods Compared to Attr_Accessor