Manar Al Saleh
Manar Al Saleh

Reputation: 365

c# how can i click button in webbrowser ducument if the element has on ID?

i have a c# web browser and when it loads the page i want the program to click on Element

i found he way to click this element when i know the ID

   htmlelement    ele = webBrowser1.Document.GetElementById("the ID"); if (ele != null)
                ele.InvokeMember("click");

but some elements have no ID or changeable ID how can i do this by value or class or something else instead of ID ??

the web page is java page maybe a got the the source code but what is the right way to do that

and if i know how to identify the element how could i change the value if the element is a textbox ??

Upvotes: 0

Views: 1324

Answers (2)

openshac
openshac

Reputation: 5155

You could try using a web automation tool like http://watin.org/ It will do everything you want and more.

Have a look here from more information: Website Automation Using C# and WebBrowser

Upvotes: 0

erikkallen
erikkallen

Reputation: 34391

Something like

var elems = webBrowser1.Document.InvokeScript("document.querySelectorAll('some-css-selector')");

might work.

Upvotes: 1

Related Questions