1

I'm trying to programmatically click a series of buttons on an HTML web page which looks as follows:

<div class="srp-actions blue-button"><a class="primary-action-button label" href="/people/invite?from=profile&amp;key=243930744&amp;firstName=Will&amp;lastName=Yang&amp;authToken=p8Oz&amp;authType=OUT_OF_NETWORK&amp;connectionParam=member_desktop_search_people-vertical-module&amp;csrfToken=ajax%3A7824954558998584370&amp;trk=vsrp_people_res_pri_act&amp;trkInfo=VSRPsearchId%3A12487701484818103943%2CVSRPtargetId%3A243930744%2CVSRPcmpt%3Aprimary" data-li-result-interaction="instant-connect" data-li-success-text="Invite Sent" data-li-connect-href="/people/contacts-search-invite-submit?memIds=243930744&amp;authTokens=p8Oz&amp;authTypes=OUT_OF_NETWORK&amp;from=voltron&amp;firstName=Will&amp;lastName=Yang&amp;isAjax=true&amp;connectionParam=member_desktop_search_people-vertical-module&amp;csrfToken=ajax%3A7824954558998584370&amp;trk=vsrp_people_res_invite_act&amp;trkInfo=VSRPsearchId%3A12487701484818103943%2CVSRPtargetId%3A243930744%2CVSRPcmpt%3Aprimary">Connect</a><div class="secondary-actions-trigger"><button role="button" class="trigger"><span>Secondary Actions</span></button><ul class="menu"><li><a href="/requestList?displayProposal=&amp;destID=243930744&amp;creationType=DC&amp;authToken=p8Oz&amp;authType=OUT_OF_NETWORK&amp;trk=vsrp_people_res_sec_act&amp;trkInfo=VSRPsearchId%3A12487701484818103943%2CVSRPtargetId%3A243930744%2CVSRPcmpt%3Aprimary">Send InMail</a></li><li><a href="/forwardProfileMsg?displayCreate=&amp;profileID=0_0TL7XobJNwUxDDGHun9drH&amp;profileName=Will+Yang&amp;network=I&amp;trk=vsrp_people_res_sec_act&amp;trkInfo=VSRPsearchId%3A12487701484818103943%2CVSRPtargetId%3A243930744%2CVSRPcmpt%3Aprimary">Share</a></li></ul></div></div>

Here's the current code to find the button element and perform the action:

HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("a");

// First find and click "Connect" buttons
foreach (HtmlElement item in elements)
{
    if (item.OuterHtml.Contains("action-button label") && 
        !item.OuterHtml.Contains("Message") &&
        item.OuterHtml.Contains("OUT_OF_NETWORK"))
    {
        item.SetAttribute("href", item.GetAttribute("data-li-connect-href"));
        item.InvokeMember("Click");
    }
}

The code properly find the anchor element, but the InvokeMember method doesn't seem to yield any result, any idea what is wrong?

1 Answer 1

2

The tag you are using does not specify exactly which specific tag you need:

x = webBrowser1.Document.GetElementsByTagName("a")

Instead try :

x= webBrowser1.Document.GetElementsById("anchor_id");
x.InvokeMember("click");

Or try using following method to verify whether its the intended tag you're using via attribute.

if (element.GetAttribute(attribute).Equals(attName))
Sign up to request clarification or add additional context in comments.

4 Comments

Actually, the actual "button" is the anchor <a> element, hence there is no button element to click - the button element in the html code above is just a side button which is out of scope of this question.
@LocoBarocco Updated the answer accordingly, Check it out.
I see your point, but in the html code above, the anchor element does not have any ID tag, so won't work...
No, it's not my code, it's retrieved from LinkedIn. I managed to trigger the proper click event now, which takes me to LinkedIn's "How do you know" page, but I want to trigger the "instant" invite event, which is placed inside the "data-li-connect-href" tag. I've tried to copy that tag to the regular href tag and trigger the click, but instead I'm redirected to my LinkedIn homepage. Also tried to use that tag info in a standalone http get request but result i the same. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.