c# webbrowser Clicking a button using the onclick attribute. getattribute("onclick") does not work

Asked

Viewed 22 times

0

Hi, I’m wanting to click on a button that has the following html:

<a href="javascript:;" onclick="ExecutarLance('46368');" title="ExecutarLance" class="btn btn-custom3">LANCE</a> == $0

But the only attribute I can use is onclick, it is unique from this button, because on the site there are more buttons with the same href, title and class. If I use href, title or class the click will be on more than one button at the same time, because it uses the same attributes. I can click using the title, the code would be:

HtmlElementCollection elementButton = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement elementyButton in elementButton)
{
 if (elementyButton.GetAttribute("title") == "ExecutarLance")
 {
  elementyButton.InvokeMember("click");
 }
}

But if I use this code, the click will be on all the buttons that have that title, and there are many, and I just want to click this specific button. Using the same logic as the previous code but changing the title attribute to the onclick attribute (which is unique to the button) the code would be:

HtmlElementCollection elementButton = webBrowser1.Document.GetElementsByTagName("a");
foreach (HtmlElement elementyButton in elementButton)
{
 if (elementyButton.GetAttribute("onclick") == "ExecutarLance('46368');")
 {
  elementyButton.InvokeMember("click");
 }
}

But it doesn’t work.

  • 1

    you cannot simply invoke Function ExecutarLance('46368')?

  • With the invokescript?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.