New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
click_link 'foo' not working on links without href #379
Comments
|
Yes, agreed. I read the HTML 5 spec about it. Perhaps a better approach would be something like
where there'd be some jquery eventing on the span element, but how would capybara simulate clicking/selecting that text? For the moment I've lapsed into using href="#", which feels like a bad practice but it's working. Thanks for response and capybara - great stuff. |
I have never tried this, but I think you might be able to do |
Jo is right, that should do the trick. Personally, I'd just add the href="#" to the links, I don't think that's bad practice at all. |
Adding Unless you intend to use the effect of The 'best-practice' syntax is: <a href="javascript_required.html?doSomething" onclick="doSomething(); return false;">go</a> |
Another way to do this is to first find link than "click" on it with keyboard
Hope it helps somebody. Regards |
@jnicklas I've tried adding href='#' to my links but I run into the same issue as @pboling - my pages jump to the top when the user clicks them. Without a hack like @tomazzlender suggested, Capybara won't click something that isn't a link, and using inline javascript as @pboling suggested mixes your concerns and is generally frowned upon these days. What I've finally settled on is having a real link that is used if a browser doesn't support JS, and using But I actually got the practice of using Thanks for all your good work on Capybara. |
@michaelrkn standard is kind of a binary concept, it either is standard or it isn't. In this case, standard means the HTML5 spec. This is the relevant section:
I don't think this can be much clearer. "then it represents a hyperlink". otherwise is does not. Capybara will happily click on anything you can throw at it, by the way, it just won't find it as a link, if you do |
Thank you |
We've just stumbled upon exactly the same issue. However, find(:css, "id-of-a-tag").clickdoes not work for us. We're using Selenium as web driver (and Javascript driver). |
@anpr it needs to be a valid CSS selector
|
We do that - sorry that my comment wasn't clear on that part. To reiterate: we have a case where find(:css, "#id-of-a-tag").clickdoesn't work. |
@anpr ok, then a stack trace would be helpful, and probably opening a new issue since this one specifically has to do with click_link |
@twalpole: In the meantime, we found out that there was a bug so that the link-without-href couldn't be clicked upon. So sorry for the spam, there's no Capybara issue here. |
Does not seem to work? Is |
|
@jnicklas your suggestion of |
@jjb yep - apparently theres a bug there |
Seems it works on my Mac but failed on my Linux box with Firefox. On Linux it went to '/'. |
@terryyin This is an old closed issue - if you have a reproducible example of a problem please create a new issue with enough detail to reproduce |
Running click_link 'Title View' against
results in Capybara::ElementNotFound: no link with title, id or text 'Title View' found . Adding an empty href -
works.
So, is the code testing for links by looking for a elements with href attributes? If so, shouldn't it drop the href attribute as mandatory?
The text was updated successfully, but these errors were encountered: