前提・実現したいこと

rails+capybara(+Poltergeist)でスクレイピングをしようとしています。
aタグをクリックして次のページに移動する動きしようとしているのですがうまく動きません。

発生している問題・エラーメッセージ

Failures:

  1) test next20
     Failure/Error: click_on "次の20件"

     Capybara::ElementNotFound:
       Unable to find link or button "次の20件"
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:43:in `block in find'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/base.rb:84:in `synchronize'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:32:in `find'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/actions.rb:13:in `click_link_or_button'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:686:in `block (2 levels) in <class:Session>'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./test3.rb:30:in `block (3 levels) in <top (required)>'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./test3.rb:28:in `block (2 levels) in <top (required)>'

Finished in 7.06 seconds (files took 0.4783 seconds to load)
1 example, 1 failure

Failed examples:

ソースコード(test3.rb)

require 'capybara/rspec' 
require 'capybara/poltergeist' 
require 'capybara/dsl'

Capybara.javascript_driver = :poltergeist 
Capybara.register_driver :poltergeist do |app| 
  Capybara::Poltergeist::Driver.new(app, { 
                    js_errors: false, 
                    timeout: 1000, 
                    debug: true, 
                    phantomjs_options: [ 
                              '--load-images=no', 
                              '--ignore-ssl-errors=yes', 
                              '--ssl-protocol=any']}) 
end

Capybara.configure do |config| 
    config.run_server = false 
    config.default_driver = :poltergeist 
    config.app_host = 'http://www.mansion-review.jp/prefecture/20.html' 
end

describe "test", :type => :feature do 
  subject{ page } 
  before { visit('/') }

  it "next20", js: true do 
    within ('#saleHistorySoubaBlock') do 
      have_text "次の20件" 
      click_on "次の20件" 
    end 
  end 
end

補足情報

  • capybara (2.6.2)
  • globalid (0.3.6)
  • rails (4.2.6)
  • rspec-rails (3.4.2)

追記

広く意見を求めたい為,Stack Overflowとteratailにて同様の質問をしております。
解決しましたら、両方にて共有したいと思いますので、ご容赦ください。


コメントは改行できないのですね、教えていただきありがとうございます。
エラーメッセージが若干違うようですので、貼っておきます。

エラーメッセージ

Failures:

  1) test next20
     Failure/Error: click_on "次の20件"

     Capybara::ElementNotFound:
       Unable to find link or button "次の20件"
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:43:in `block in find'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/base.rb:84:in `synchronize'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:32:in `find'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/actions.rb:13:in `click_link_or_button'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:686:in `block (2 levels) in <class:Session>'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./test3.rb:31:in `block (4 levels) in <top (required)>'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./test3.rb:29:in `block (3 levels) in <top (required)>'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'
     # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./test3.rb:28:in `block (2 levels) in <top (required)>'

Finished in 7.67 seconds (files took 1.44 seconds to load)
1 example, 1 failure

Failed examples:

修正部分

describe "test", :type => :feature do
  subject{ page }
  before { visit('/') }

  it "next20", js: true do
    within first('#resultBlock div p') do
      within all('a').last do
        should have_text '次の20件'
        click_on "次の20件"
      end
    end
  end
end