2014-04-18 7 views
0

ruby에서 selenium을 사용하여 페이지 맨 아래로 스크롤하는 방법을 보여줄 수 있습니까? 나는이ruby에서 셀레늄을 사용하여 아래로 스크롤하는 방법

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

을 읽을 수는 있지만이 link에, 나는 모든 요소를 ​​찾을 수 없습니다. 발견 된 것과 같은 요소가없는 길을 보여줄 수 있습니까? 고맙습니다!

+0

좋은 아이디어는 HTML 문서를 제공하는 것입니다 .. 내가 링크 내 질문을 편집 –

+1

@ArupRakshit, 당신은 나를 도와 드릴까요? 고맙습니다! –

+0

페이지가 동적으로로드되고 있습니다. –

답변

5

페이지를 보면 클래스 바닥 글과 div가 표시되지 않았습니다. 이것이 요소를 찾을 수없는 이유 일 수 있습니다.

나를 위해, 마지막으로 보이는 요소는 바탕 화면 인 것처럼 보입니다. 즉, div와 class pic이 있습니다. 마지막 사진을 가져 와서 다음을 사용하여 스크롤 할 수 있습니다. 우리는 모든 그림을 찾은 다음 컬렉션에서 마지막 그림을 가져옵니다.

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

마지막 배경 화면으로 스크롤 한 후 페이지로드가 완료 될 때까지 기다리는 것이 좋습니다. 예를 들어, 다음 이미지 카운트가 증가 될 때까지 기다립니다 :

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 
+0

우수 .. 감사합니다. –

관련 문제