我试图自动化 rediff.com 。我从一页转到另一页,但是当我回来时,我得到了 staleException 。我尝试了很多但无法修复它。我也附上代码片段。任何帮助,将不胜感激。
@driver.get " http://shopping.rediff.com/?sc_cid=inhome_icon "
@driver.manage.window.maximize
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # 秒
开始
element = wait.until { @driver.find_element(:xpath,".//*[@id='popular_cat']") }
确保
box=@driver.find_element(:xpath,".//*[@id='popular_cat']")
结束链接=box.find_elements(:tag_name,"a")
puts "总链接数:#{links.size}"
links.each 做 |i|
puts "--------------------"
puts "Value of all links is:#{i.text}"
i.click
puts "Title of page is :#{@driver.title}"
@driver.get "http://shopping.rediff.com/?sc_cid=inhome_icon"
box=@driver.find_element(:xpath,".//*[@id='popular_cat']")
links=box.find_elements(:tag_name,"a")
end