Sometimes Capybara click_link doesn't work

I am using Capybara 1.0.0 with default configuration.

click_link "some existing text" # - sometimes - does not work. weird.

find_link "some existing text" # always works

This may be a synchronization problem; or maybe not because find_link works fine fine.

I checked the resulting output file with save_and_open_page, this is also normal. In addition, I increased the wait time, etc. But help did not help.

Before I go completely to the source of Capybara. What do you think went wrong?

Hi

+7
source share
3 answers

Whenever I get intermittent problems with my tests, one of the first things I check is the sequence in which they are executed.

Depending on how you install Rspec, this probably randomizes the order in which the specifications are executed each time the package is run. This means that sometimes everything passes, and sometimes not.

Rspec will output an initial value that you can use to restart the tests in the same order for debugging purposes.

0
source

Try using this syntax click_link('', href: some_path) .

0
source

The link can be displayed by another element (for example, a pop-up window) or activated by Ajax some time after the page loads. It greatly depends on which page you are working with.

As general advice, I would recommend using crawlers directly, for example:

  # Note :visible => true, it will throw an error if element is overlapped find(:xpath, "//a[.='some existing text']", visible: true).click # Another approach wait_until(15) { first(:xpath, "//a..", visible: true) }.click 
0
source

All Articles