Javascripted Button

SligStorm

New member
Joined
Oct 12, 2011
Messages
1
Programming Experience
3-5
in vb.net how would I click a javascripted button on a webpage?
the standard Document.GetElementById doesn't seem to work.

This is the buttons code
VB.NET:
<a onclick="FriendCenter.AddFriend('name')" href="#">Add to Friends List</a>

and this is the javascript for its action

VB.NET:
        this.AddFriend = function(gamerTag) {             gamerTag = $.trim(gamerTag); // trim leading and trailing whitespaces             if (gamerTag != "") {                 fcAction('/en-GB/FriendCenter/SendFriendRequest', gamerTag);             }             return false;         };

How would I have my form button execute this javascript?
 
GetElementById works if the element has an id, if it doesn't it can't work and you have to use other methods to get a reference to that element. For example, since you haven't posted any clues as to context, a brute force way could be to get all A hyperlink elements and check each if they have correct inner text. The HtmlDocument for example has a Links property that contains the hyperlinks collection. Context means that a node has a specific place in the documents element tree, and this can make it easier to locate, for example it could be a child of an element that does have an id, or it could be the child of a specific kind of element that by itself is easier to locate than a common A element.
 
GetCurrentWebDoc.parentWindow.execScript("skipButt on()", "javascript")
That could be an idea, though script execution already exist natively in .Net with HtmlDocument.InvokeScript method, but the problem may be that one need to find the button element anyway if there are different arguments that needs to be passed, in the request here the button calls a script with string argument "name".
 
agree, i pullout that stored here at my hard drive along time ago. now i forget everything. btw Sir John, can you check out the thread i made.
Thanks
 
Back
Top