# Why not giving every link, button etc. tag a unique id attr?

**URL:** <https://www.ruby-forum.com/t/why-not-giving-every-link-button-etc-tag-a-unique-id-attr/89999>\
**Category:** Rails\
**Created:** [March 24, 2007, 9:21pm UTC](https://www.ruby-forum.com/t/why-not-giving-every-link-button-etc-tag-a-unique-id-attr/89999 "2007-03-24T21:21:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 24, 2007, 9:21pm UTC](https://www.ruby-forum.com/t/why-not-giving-every-link-button-etc-tag-a-unique-id-attr/89999/1 "2007-03-24T21:21:04Z")

</div>

Hi all

I’m playing around with Selenium IDE for creating automated acceptance  
tests for my RoR projects (very cool tool by the way).

Often it’s the easiest way to pass a HTML-tag ID to Selenium to perform  
actions such as clicking on a link or submitting a form.

Sadly Rails does not automatically create ID attrs for many tags like  
links or buttons.  
Has this a special reason? Or is it safe to customize the link\_to etc.  
helpers so they create ID’s automatically?

Thanks for help  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 25, 2007, 3:21am UTC](https://www.ruby-forum.com/t/why-not-giving-every-link-button-etc-tag-a-unique-id-attr/89999/2 "2007-03-25T03:21:14Z")

</div>

On Mar 24, 3:21 pm, Joshua M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Sadly Rails does not automatically create ID attrs for many tags like  
> links or buttons.  
> Has this a special reason? Or is it safe to customize the link\_to etc.  
> helpers so they create ID’s automatically?

No special reason, other than how would Rails generate the IDs in a  
predictable fashion? If you are not (or can not) cache the generated  
html from a template, then the template will be evaluated each time  
form the server, so Rails would have to have some way of making sure  
all the IDs it generates are unique across the page - perhaps unique  
across the whole app depending on what you’re testing. Not to  
mention, you would probably want Rails to use the same IDs for the  
same elements each time so your tests don’t break… So I think you  
can see it’s not one of those no-brainers that it might seem to be.

Why don’t you just specify the ID yourself for the elements that need  
it? It’s pretty easy to add your own HTML IDs to all of your link\_to  
statements, or like you said, create your own helper that will do it  
for you,

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 25, 2007, 11:24am UTC](https://www.ruby-forum.com/t/why-not-giving-every-link-button-etc-tag-a-unique-id-attr/89999/3 "2007-03-25T11:24:17Z")

</div>

Thanks, I got the point. Anyway I found that with Selenium you can pass  
different types of locators, so I don’t need an ID necessarily.  
“link=Link Caption” does it perfectly, too. 🙂
