Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Note:
I am getting particular html element with help of page scraping
but unable to perform click action on that particular element. i am
invoked events like onmouseup,onmousedown,Onclick,click etc... but it
cant be working. can u suggest me?
C#
 HtmlElement dropdownId = contentDoc.GetElementById("website");
 HtmlElementCollection liTags = dropdownId.GetElementsByTagName("li");
 foreach (HtmlElement liTagInner in liTags)
  {
    if (liTagInner != null && liTagInner.InnerText != null)
  {
if(liTagInner.InnerText.Equals("about",
StringComparison.InvariantCultureIgnoreCase))
 {
liTagInner.InvokeMember("click");
//
}
}
}
Posted
v2
Comments
RamanaReddy V 15-Dec-15 9:13am    
Thanks for ur comments but i want to click on that html element in run time to navigate to another page.

HtmlElement dropdownId = contentDoc.GetElementById("website");
HtmlElementCollection liTags = dropdownId.GetElementsByTagName("li");
foreach (HtmlElement liTagInner in liTags)
{
if (liTagInner != null && liTagInner.InnerText != null)
{
if(liTagInner.InnerText.Equals("about",
StringComparison.InvariantCultureIgnoreCase))
{
liTagInner.Click(); // i want to click on that html element in run time to navigate to another page.
//
}
}
}

1 solution

Hi,

You are trying to invoke an client side function from the server side?

SingalR would a good tool to do so apart from reflection.

OR

You could add script which will call that click function on page load

Example : https://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900