简体   繁体   中英

How do I simulate web page button click in c#

I know it can be done by webBrower.Document.GetElementById("Id_Of_Element").InvokeMembers("Click") method by I have trouble finding it's ID. is there any other way I can do that. Web Page URL is this http://www.magtifun.ge/index.php?page=1&lang=en I need to simulate press on "Sign In" Button !

You should have a look at webdriver and selenium. These are tools for automated testing.

webdriver and selenium

If webBrower.Document.GetElementById("Id_Of_Element").InvokeMembers("Click") works then you can use this:

webBrower.Document.GetElementById('<%= YourElement.ClientID %>').InvokeMembers("Click")

or you can try this:

document.getElementById('<%= YourElement.ClientID %>').click()

Returning to the problem with IDs, starting from ASP.NET 4.0 you can use ClientIDMode property for you element. And if you set it into Static then the ClientID value will be set to the value of the ID property:

<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static" />

will be rendered as something like this:

 <input id="TextBox1" name="ctl00$MasterPageBody$ctl00$TextBox1" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM