How to reference an html button in C #

0

I have the following HTML code snippet:

ThiscodebelongstoapageofanAirOS(internetradio)radio.

IneedtoreferencethisbuttoninsideaprogrammadeinWindowsFormsandmakeafunctionforittobeexecutedandtheradioreboot.

Iwasonlyabletogetelementswithanidattribute,asfollows:

HtmlElementusername=webBrowser1.Document.GetElementById("username");

How do I reference this button that has no "id" field? Remembering that the HTML code is not mine, I can not edit it and put the "id" field.

I'm currently using the WebBrowser component, would I have some other way to access the radio and reboot without using WebBrowser?

Thank you.

    
asked by anonymous 11.01.2017 / 19:47

2 answers

3

Try to do this:

var button = myWebBrowser.Document.GetElementsByTagName("input")
         .Cast<HtmlElement>()
         .FirstOrDefault(m => m.GetAttribute("type") == "submit");
    
11.01.2017 / 20:17
1

You can try to get this "button" by type ..

var inputs = document.getElementsByTagName('input');

In this case you have the inputs of the screen. This can go wrong if you have more inputs than you want to select, then you would need some unique identifier.

    
11.01.2017 / 20:30