c# - To click a button with the class having many of the same class -


when click button on web page in webbrowser, have element class following code :

htmlelementcollection classbutton = webbrowser1.document.all; foreach (htmlelement element in classbutton)  {    if (element.getattribute("classname") == "button color")     {        element.invokemember("click");     }  } 

i want click on button has class button color twelve buttons same class, , want simulate click on first 1 only.

i decided move comments answer. since juansanchez1993 wanted simulate click on first button out of twelve have same class name, simple solution add break in foreach loop after invokemember called button. here example of mean:

htmlelementcollection classbutton = webbrowser1.document.all;  foreach (htmlelement element in classbutton) {     if (element.getattribute("classname") == "button color")     {        element.invokemember("click");        break; //add break after invokemember called invoke 1st button click.     } } 

here mean in comments using system.linq call specific class button:

htmlelementcollection classbutton = webbrowser1.document.all.where(e => e.getattribute("classname") == "button color") htmlelementcollection;  classbutton[index].invokemember("click"); 

disclaimer: never used htmlelementcollection before sure add comments if having issue this.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -