SAbboushi
asked on
What DOM properties and methods can I use to click on this element?
I wish I could modify the DOM (add a class or an id to the element...) but I cannot.
I need to click on this element:
I know I can select all anchor elements with e.g.
Not sure if that is the easiest way to begin, or whether there is a better way.
Can someone please provide the code that will click on that href using DOM properties/methods?
Thanks-
Sam
I need to click on this element:
<a href="javascript:__doPostBack('Results$_ctl5$_ctl0','')" style="color:#003069;">Address2</a>
I know I can select all anchor elements with e.g.
arefs := document.getElementsByTagName("a")
Not sure if that is the easiest way to begin, or whether there is a better way.
Can someone please provide the code that will click on that href using DOM properties/methods?
Thanks-
Sam
Just add an id to the element and the you can access it with document.getElementById()
Cd&
Cd&
@Cd&
I wish I could modify the DOM (add a class or an id to the element...) but I cannot.
Yes I saw that and if they actually have such limited access that they cannot change a line of code then whoever or whatever is imposing that kind of restriction is obtuse, because you can do all kinds of damage in the DOM while at most you can only screw up a line of code if you have access.
@SAbboushi,
What we really need to know is what kind of nutty project puts you in a position where you cannot access the code but you have the ability to use scripting of the DOM that could literally destroy the page.
Cd&
@SAbboushi,
What we really need to know is what kind of nutty project puts you in a position where you cannot access the code but you have the ability to use scripting of the DOM that could literally destroy the page.
Cd&
ASKER
Maybe I have misled as a result of my "noobness"...
I do not have control over the webpage source; but I can change the DOM interactively by code in order to manipulate it (...if I said that correctly) ; )
By this, I meant in the original html source; but if there is a way to add an id to the DOM after I have read the DOM, that would be good.
The href I want to click on is an element within a table:
TableHTML := document.getElementById("T able1").in nerhtml
which contains e.g.
In the above example, I want to click on: <a href="javascript:__doPostB ack('Resul ts$_ctl5$_ ctl0','')" >
I do not have control over the webpage source; but I can change the DOM interactively by code in order to manipulate it (...if I said that correctly) ; )
I wish I could modify the DOM (add a class or an id to the element...) but I cannot.
By this, I meant in the original html source; but if there is a way to add an id to the DOM after I have read the DOM, that would be good.
The href I want to click on is an element within a table:
TableHTML := document.getElementById("T
which contains e.g.
<tbody><tr>
<td align="Center"> </td><td><a href="javascript:__doPostBack('Results$_0','')" style="">Address</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_1','')" style="">Owner</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_2','')" style="">Price</a></td><td><a href="javascript:__doPostBack('Results$_3','')" style="">Bed</a></td><td><a href="javascript:__doPostBack('Results$_4','')" style="">Bath</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_5','')" style="">SqFt</a></td>
</tr><tr>
<td align="Center"><input id="Results__ctl3" type="checkbox" name="Results:_ctl3" onclick="disableCheckBoxes(this.form);__doPostBack('Results$_ctl3$cbItem','')" language="javascript">
</td><td><a href="javascript:__doPostBack('Results$_ctl5$_ctl0','')">2707 RALPHO ST</a></td><td>JOHN SMITH</td><td align="Right">$237,416</td><td>04</td><td>02/1 </td><td align="Right">3,152</td>
</tr>
</tbody>
In the above example, I want to click on: <a href="javascript:__doPostB
As Cobol said, it does seem odd that you can inject javascript into a document but can't edit the HTML. There's no easy way of selecting that link because it has no unique identifier. You could do some complicated traversal to select it, but you'd need some consistency - i,e if it's always the last link in that table then you could use:
$('#Table1 a').last()
You could loop through every link and do a logical comparison against the href (but that's really messy)
Your best bet is to get an ID (or at least a Class) added to the A. If you can't get the HTML edited then you're probably out of luck on this one
$('#Table1 a').last()
You could loop through every link and do a logical comparison against the href (but that's really messy)
Your best bet is to get an ID (or at least a Class) added to the A. If you can't get the HTML edited then you're probably out of luck on this one
ASKER
>> but can't edit the HTML
Let me make sure I understand: the webpage was created by another organization; we want to programatically navigate to an href on their page. I would consider it unreasonable for me to contact another organization and ask them to change their website (i.e. add an id to an element) to accommodate our desire for an easy solution to have our code click on that link on their website.
That's what I mean by I cannot change the source HTML
>> There's no easy way of selecting that link because it has no unique identifier.
But "Results$_ctl5$_ctl0" is a unique identifier... or maybe there is a definition for "unique identifier" that I haven't yet learned...? I'm new a this ; )
Let me make sure I understand: the webpage was created by another organization; we want to programatically navigate to an href on their page. I would consider it unreasonable for me to contact another organization and ask them to change their website (i.e. add an id to an element) to accommodate our desire for an easy solution to have our code click on that link on their website.
That's what I mean by I cannot change the source HTML
>> There's no easy way of selecting that link because it has no unique identifier.
But "Results$_ctl5$_ctl0" is a unique identifier... or maybe there is a definition for "unique identifier" that I haven't yet learned...? I'm new a this ; )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your post. Seems you have misunderstood mine.
ASKER
k thanks
We need to see it 'in context' to give you an answer