0

Can you show me the way to use selenium in ruby to scroll down to bottom of page? I read this

element = driver.find_element(:xpath, "//div[@class='footer small']")
element.location_once_scrolled_into_view

but in this link, i can't find any element. Can you show me the way without element like that found. Thank you!

5
  • Good idea would be to give the HTML document.. Commented Apr 18, 2014 at 19:36
  • 1
    @ArupRakshit i edited my question with the link, can you help me? thank you! Commented Apr 18, 2014 at 19:38
  • page is being loaded dynamically. Commented Apr 18, 2014 at 19:40
  • @ArupRakshit: But as I see, To continue load it, we must scroll down Commented Apr 18, 2014 at 19:42
  • have you tried using find_element(:css, "#mm-blocker") seems like the last element on the page to me. Commented Apr 18, 2014 at 20:42

1 Answer 1

5

When I looked at the page, I did not see a div with class footer. This might be why you cannot find the element.

For me, the last visible element appears to be the wallpapers - ie div with class pic. You can get the last picture and scroll to it using the following. Note that we find all of the pictures and then take the last one in the collection.

last_picture = driver.find_elements(:css, 'div.pic').last
last_picture.location_once_scrolled_into_view

After you scroll to the last wallpaper, you will want to wait for the page to finish loading. For example, the following will wait until the image count increases:

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://www.mobileswall.com/'

# Check how many elements are there initially  
puts driver.find_elements(:css, 'div.pic').length
#=> 30

# Scroll to the last image
driver.find_elements(:css, 'div.pic').last.location_once_scrolled_into_view

# Wait for the additional images to load
current_count = driver.find_elements(:css, 'div.pic').length
until current_count < driver.find_elements(:css, 'div.pic').length
  sleep(1)
end

# Check how many elements are there now
puts driver.find_elements(:css, 'div.pic').length
#=> 59
Sign up to request clarification or add additional context in comments.

Comments

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.