teamcapybara / capybara

Acceptance test framework for web applications

Home Page:http://teamcapybara.github.io/capybara/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Click links that span multiple lines

rlgreen91 opened this issue · comments

Background:
Our main web-app for my company uses ActiveAdmin for the bulk of our admin views and functionality. I added a new column to an index page displaying a list of records in a table. In a corresponding feature spec, the contents of the first column began to wrap - this cell contains a link to a profile page for the individual record with the name attribute of the record as the link text.

Problem:
This link with automatic text wrapping caused any Capybara commands to click the link to fail. click_link does not support regex and would try to literally match the multiline modifier at the end. For example, click_link /{record.name}/m would try and fail to find a link with the text "Example Text/m". Trying to use find("a") and specifying the text using a regex or the href value would return an error that firing a click failed due to the detection of another element at the same position. In other words, it would fail to recognize that it was a single link element spanning multiple lines.

Request:
Ideally, it would be great if click_link could be extended to account for links that span multiple lines automatically or via a value in an options hash. If that's not an optimal solution, then perhaps click_link could be extended to allow regex arguments in addition to strings so that the user can specify the multiline modifier there.

This has nothing to do with multi-line regex because there is no actual line feed/carriage return inserted into the text it's just a layout wrapping (as evidenced by the fact that you can find the link without actually specifying any extra things in the locator. The issue here is that Capybara clicks the middle of the link - which when the link wraps happens to be a position that is no longer on the link (hence the error about it clicking another element). The solution in your case is to either set the window dimensions larger so things don't wrap or
split the find/click and use an offset find_link(record.name).click(x: blah, y: blah) with the actual values of x and y dependent on what other settings you have (offset from corner or center)