TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sourabh Choubey
NA
236
44k
how to call a html image button clicik not by clicking on...
Mar 31 2017 2:24 AM
how to call a html image button clicik not by clicking on html image but by calling the click method in your code.
this is my html image type
<input type="image" name="ctl00$CphPageMiddle$ctl00" ïd="btnLogin" src="../Style/LoginPage/img/signin.png" class="img-responsive" style="cursor: pointer">
now i want to call a click by my code that is written in my class file.First of all i load all the html element of the particular page (this is the login page) .Now i want to fire a button from my class file.With the help of web browser element i load all the contents of this page and done the following things..
Console.WriteLine(wb.Document.Body.InnerHtml);
HtmlDocument doc = wb.Document;
HtmlElement username = doc.GetElementById("CphPageMiddle_txtUserID");
HtmlElement password = doc.GetElementById("CphPageMiddle_txtPassword");
NOW I SET ATTRIBUTES TO USERNAME AND PASSWORD
username.SetAttribute("value", "ID");
password.SetAttribute("value", "PWD");
NOW I WANT TO KNOW HOW I CAN FIRE THE ABOVE HTML INPUT TYPE IMAGE
AND AFTER FIRE THE HTML ELEMENT GO TO THE RESPECTIVE PAGE.
HERE IS MY FULL CODE GIVEN BELOW-
class Program
{
private static bool completed = false;
private static WebBrowser wb;
[STAThread]
static void Main(string[] args)
{
wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
//wb.Navigate("http://www.erecsdharge.com");
wb.Navigate(@"http://www.abc.com/default.aspx");
while (!completed)
{
Application.DoEvents();
Thread.Sleep(100);
}
Console.Write("\n\nDone with it!\n\n");
Console.ReadLine();
}
static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
if (!completed)
{
Console.WriteLine(wb.Document.Body.InnerHtml);
HtmlDocument doc = wb.Document;
HtmlElement username = doc.GetElementById("CphPageMiddle_txtUserID");
HtmlElement password = doc.GetElementById("CphPageMiddle_txtPassword");
// HtmlElement submit = doc.get("btnLogin");
username.SetAttribute("value", "ID");
password.SetAttribute("value", "PWD");
// submit.InvokeMember("click");
//after click on login button return to main page by navigate to the main page here.....
wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompletedlanding);
wb.Navigate(@"http://www.abc.com/mainpage.aspx");
if (wb.Url.ToString().IndexOf("LandingPage.aspx") > -1)
{
completed = false;
while(!completed)
{
Application.DoEvents();
Thread.Sleep(100);
}
}
Console.WriteLine();
completed = true;
}
}
catch(Exception ex)
{
throw ex;
}
}
static void wb_DocumentCompletedlanding(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
if (!completed)
{
Console.WriteLine(wb.Document.Body.InnerHtml);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
Any help will be greatly appreciated.Please give me the needfull help.Thanks.
Reply
Answers (
4
)
Creating PPT slide with chart and export using C# .net web a
RDLC Report Designer