Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ruby中使用selenium向下滚动到底部_Ruby_Selenium_Scroll_Selenium Webdriver - Fatal编程技术网

如何在ruby中使用selenium向下滚动到底部

如何在ruby中使用selenium向下滚动到底部,ruby,selenium,scroll,selenium-webdriver,Ruby,Selenium,Scroll,Selenium Webdriver,您能告诉我如何在ruby中使用selenium向下滚动到页面底部吗?我读了这个 element = driver.find_element(:xpath, "//div[@class='footer small']") element.location_once_scrolled_into_view 但在这里,我找不到任何元素。你能告诉我没有那种元素的路吗。谢谢大家! 当我查看页面时,没有看到带有类页脚的div。这可能就是您找不到元素的原因 对我来说,最后一个可见的元素似乎是墙纸——即带有pi

您能告诉我如何在ruby中使用
selenium
向下滚动到页面底部吗?我读了这个

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

但在这里,我找不到任何元素。你能告诉我没有那种元素的路吗。谢谢大家!

当我查看页面时,没有看到带有类页脚的div。这可能就是您找不到元素的原因

对我来说,最后一个可见的元素似乎是墙纸——即带有pic类的div。您可以获取最后一张图片,并使用以下命令滚动到它。请注意,我们找到了所有图片,然后拍摄了收藏中的最后一张

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
需要“selenium webdriver”
driver=Selenium::WebDriver.for:firefox
driver.navigate.to'http://www.mobileswall.com/'
#检查最初有多少个元素
放置driver.find_元素(:css,“div.pic”).length
#=> 30
#滚动到最后一个图像
driver.find_元素(:css,'div.pic')。last.location_一次将_滚动到_视图中
#等待加载其他图像
当前\u计数=驱动程序。查找\u元素(:css,'div.pic')。长度
直到当前_count 59

当我查看页面时,没有看到带有类页脚的div。这可能就是您找不到元素的原因

对我来说,最后一个可见的元素似乎是墙纸——即带有pic类的div。您可以获取最后一张图片,并使用以下命令滚动到它。请注意,我们找到了所有图片,然后拍摄了收藏中的最后一张

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
需要“selenium webdriver”
driver=Selenium::WebDriver.for:firefox
driver.navigate.to'http://www.mobileswall.com/'
#检查最初有多少个元素
放置driver.find_元素(:css,“div.pic”).length
#=> 30
#滚动到最后一个图像
driver.find_元素(:css,'div.pic')。last.location_一次将_滚动到_视图中
#等待加载其他图像
当前\u计数=驱动程序。查找\u元素(:css,'div.pic')。长度
直到当前_count 59

给HTML文档是个好主意。@ArupRakshit我用链接编辑了我的问题,你能帮我吗?非常感谢。页面正在动态加载。@ArupRakshit:但如我所见,要继续加载,我们必须向下滚动。您是否尝试过使用
find_元素(:css,“#mm blocker”)
对我来说似乎是页面上的最后一个元素。最好是给HTML文档。@ArupRakshit我用链接编辑了我的问题,你能帮我吗?非常感谢。页面正在动态加载。@ArupRakshit:但正如我看到的,要继续加载,我们必须向下滚动。您是否尝试使用
find_元素(:css,“#mm blocker”)
在我看来似乎是页面上的最后一个元素。