I'm automating some things on a website. I need to check if a "Next" button is there on a page and then click on it. This is the HTML.
<a href="javascript:goToPage(2);"><span class="txt_purple"></span><img align="absmiddle" src="/icon_next.jpg" border="0" /></a>
I can use getElementsByTagName('img') to find the image and then how do I do the click?
UPDATED WITH ANSWER:
Adding an id isn't possible in this case. I don't have control over the webpages. It is somebody else's site so I have to do with what's already there. This is what I did:
var e = document.getElementsByTagName('img');
for (var i = 0; i < e.length; i++) {
if (e[i].hasAttribute('src') && e[i].getAttribute('src') == '/icon_next.jpg') {
e[i].click();
break;
}