Capybara click_link sometimes doesn't work
I'm using Capybara 1.0.0 with default configuration.
click_link "some existing text" # --sometimes-- doesn't work. weird.
find_link "some existing text" # always works
This may be a timi开发者_JS百科ng problem; or maybe not because find_link works brilliantly ok.
I've checked the produced output file via save_and_open_page, it's ok too. Also, I've increased the wait time etc. But, neither did help.
Before I goto the source of Capybara completely. What do you think that is gone wrong?
Regards
Whenever I'm getting intermittent problems with my tests one of the first things I check is the sequence they are being run in.
Depending on how you have Rspec setup, it is probably randomising the order the specs are run in each time you run the suite. This means sometimes everything passes and other times not.
Rspec will output a seed value you can use to re-run the tests in the same order for debugging purposes.
Try to use this syntax click_link('', href: some_path)
.
The link may be ovelapped with another element (like Popup window), or it is activated by Ajax after a while after page is loaded. It's strongly depends of what kind of page you operate with.
As a general tips, I would recommend to use finders directly, like:
# 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
精彩评论