Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am a mechanical engineer and I am learning JavaScript to automate webpage in IE. Can anybody provide java script for clicking LI objects in HTML page?

I tried using below code but it doesn't work.

document.getElementByID("432869881541.5918").click()

HTML code looks like below.

<UL>
<LI class=link id=1360318910295.6645 menuUID="1360318910295.6645">
<SPAN class=icon style="BACKGROUND-IMAGE: url(../common/images/utilMmenuBullets.gif)"></SPAN><SPAN>Select...</SPAN></LI>
<LI class=link id=432869881541.5918 menuUID="432869881541.5918"><SPAN class=icon style="BACKGROUND-IMAGE: url(../common/images/utilMmenuBullets.gif)"></SPAN><SPAN>Change...</SPAN></LI>
<LI class=link id=1402867405344.4795 menuUID="1402867405344.4795"><SPAN class=icon style="BACKGROUND-IMAGE: url(../common/images/utilMmenuBullets.gif)"></SPAN><SPAN>Edit...</SPAN></LI>
<LI class=link id=1056960102523.8238 menuUID="1056960102523.8238"><SPAN class=icon style="BACKGROUND-IMAGE: url(../common/images/utilMmenuBullets.gif)"></SPAN><SPAN>Change Project Member...</SPAN></LI>
<LI id=1271335933173.4301 menuUID="1271335933173.4301">
<HR>
</LI>
</UL>
share|improve this question
// get the first unordered list
var ul = document.getElementsByTagName('ul')[0];

// get all list elements in unordered list
var items = ul.getElementsByTagName('li');

// executed when list item is clicked
function callback() {
   console.log(this);
   var menuUID = this.getAttribute('menuuid');

   console.log('id: ' + this.id);
   console.log('menuUID' + menuUID);
}

// loop over each list item
for (var i=0; i<items.length; i++) {
   // current list item
   var item = items[i];
   // add 'click' callback to the list element
   item.addEventListener('click', callback);
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.