0

I've been trying to login to a site using a WebBrowser control automatically by using the GetElementByTag / GetElemenByName methods but with not much success. (WFA - C#)

I believe the main reason is the fact that the site is in JavaScript.

I've done some research and found two methods:

  1. by mimicking the site login form I could use something called POST. (or something of that sort)
  2. inject a javascript input to all the input fields in the site

I have no idea how to approach this problem, and due to my total lack of experience with javaScript or any web based programing, I could realy use any advice or solution for the matter at hand.

/** EDIT 1 thank you for your quick response. ive tried to use your code and still facing the same exception throw..

here is the code : (I trimmed it a bit)

   public WorkerClass(string url)
    {
     webBrowser1 = new WebBrowser();
     webBrowser1.Navigate(url);
     webBrowser1.Document.GetElementById("c_Username").InnerText = "?????";
     webBrowser1.Document.GetElementById("c_Password").InnerText = "?????";
    }

and I get a "System.NullReferenceExeption" on the username line above.

the site im trying to access is - "http://www.gool.co.il"...maybe my approach is wrong?!

1 Answer 1

1

You can use web browser control ,just find element id on your target page and fill them.

I write a simple one for you:

public Form1()
        {
            InitializeComponent();
            //navigate to you destination 
            webBrowser1.Navigate("https://www.certiport.com/portal/SSL/Login.aspx");
        }
        bool is_sec_page = false;
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (!is_sec_page)
            {
                //get page element with id
                webBrowser1.Document.GetElementById("c_Username").InnerText = "username";
                webBrowser1.Document.GetElementById("c_Password").InnerText = "pass";
                //login in to account(fire a login button promagatelly)
                webBrowser1.Document.GetElementById("c_LoginBtn_c_CommandBtn").InvokeMember("click");
                is_sec_page = true;
            }
            //secound page(if correctly aotanticate
            else
            {
                //intract with sec page elements with theire ids
            }

        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.