-2

How do I find a element Id that is autogenerated which means that element will never have the same id once the browser reloads.

There's a way where I find that element string let's say "Click" by doing this in jquery:

$( "a:contains('Click')" ); which gives me this,

<a href="test.com" id=alwayschanging >Click</a>

How do I send a click event to that id or string?

TheKid
  • 19
  • 6
  • possible duplicate of [How can I get the ID of an element using jQuery?](http://stackoverflow.com/questions/3239598/how-can-i-get-the-id-of-an-element-using-jquery) – Imashcha May 15 '15 at 15:47
  • Please decide whether your question is "How do I find a element Id that is autogenerated" or "How do I send a click event to that id or string?" – Imashcha May 15 '15 at 15:54

2 Answers2

1

Use a selector which doesn't make use of the ID

$('a[href="saveFile"]').click()

If you can't use jQuery you will have to use

var els = document.getElementsByTagName("a");
for (var i = 0, l = els.length; i < l; i++) {
    var el = els[i];
    if (el.text === 'Click') {
        el.click()
    }
}
thodic
  • 2,229
  • 1
  • 19
  • 35
0

You don't need the id to send a click event. Just click it

$( "a:contains('Click')" ).click()
Farzher
  • 13,934
  • 21
  • 69
  • 100