Re: Method of element identification and emulation of click event
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Thu, 29 May 2008 18:57:08 -0700 (PDT)
On May 30, 7:59 am, ZZyZX <nos...@xxxxxxxxxx> wrote:
I wish to uniquely identify the below button element embedded
among many other button elements in a web page and call the click
event on it to automatically navigate to the next page in a
sequence of pages. Similar in action to automated login.
<INPUT class=submitn onclick="window.location='/newstuff?
newstuffupdate=prefs&type=cfilter&index=1&from=zzyzx'"
type=button value="Search Now">
Since the above button element has no id or name tag I can't see
any way of success with;
var tag=document.getElementById("foo").click()";
Also, if it matters, this input element and many others of the
class=submitn are not wrapped in a <form> </form> block, they do
all reside in a <div> </div> block.
http://www.javascriptkit.com/domref/documentmethods.shtml
does have a close approximation of what could be used.
Under heading - getElementsByName(name)
<div name="george">f</div>
<div name="george">f</div>
The HTML 4 specification does not include a name attribute for div
elements.
<script type="text/javascript">
var georges=document.getElementsByName("george")
While that "works", it should not be expected to always work where the
name attribute is not standard.
for (i=0; i< georges.length; i++)
// do something with each DIV tag with name="george". Firefox only.
I guess you discovered that it doesn't work in IE (at least).
</script>
but the above still leaves the identification of the input
button unsolved.
Any insights or suggestions?
In order to uniquely identify an element in a page, you have to decide
what attributes it has that make it unique and use them.
One method is to use getElementsByTagName('input') - each element in
the returned collection has an index relative to other inputs in the
DOM. Provided the DOM structure is not altered to the extent that the
input's index changes, it will reliably find the same element every
time.
BTW, getElementsByClassName is specified as part of HTML 5 and has
been implemented by some browsers[1], your own function should mimic
the API and perhaps also see if the host function can be used rather
than a javascript native function.
1. Supported by Safari, Firefox, Opera and the HTML 5 working
document:
<URL: http://www.whatwg.org/specs/web-apps/current-work/#getelementsbyclassname
--
Rob
.
- Follow-Ups:
- References:
- Prev by Date: Re: Attach a class method to event handler
- Next by Date: Re: Attach a class method to event handler
- Previous by thread: Re: Method of element identification and emulation of click event
- Next by thread: Re: Method of element identification and emulation of click event
- Index(es):