-1

I am trying to login into a website using a c# program. Right now my program accesses the website and opens the link I want but is redirected to a page where it shows a link to login I go to that and it shows a log in form. Right now I just have this program running in a console application and when I put it into a winform I'd like for the only input to be the username and password.

I have tried several different things using webclient, MSHTML and SHDocVw, and HTTPRequest.

<fieldset class="input">
    <p id="com-form-login-username">
        <label for="username">Username</label><br />
        <input name="username" id="username" type="text" class="inputbox" alt="username" size="18" />
    </p>
    <p id="com-form-login-password">
        <label for="passwd">Password</label><br />
        <input type="password" id="passwd" name="passwd" class="inputbox" size="18" alt="password" />
    </p>
        <p id="com-form-login-remember">
        <label for="remember">Remember Me</label>
        <input type="checkbox" id="remember" name="remember" class="inputbox" value="yes" alt="Remember Me" />
    </p>
        <input type="submit" name="Submit" class="button" value="Login" />
</fieldset>

I would like to be able to access the first link and pull all the source code to grab the information that I need.

2 Answers2

0

I think your looking for selenium its a really useful automation library it also can run in headless mode which means that it wont show the google tab where the automation is happening. you can also get an elements value and many more things

you can see more at : https://www.seleniumhq.org/

Tutorial: https://www.guru99.com/selenium-csharp-tutorial.html

Omar
  • 48
  • 2
  • 7
0

I managed to figure out something that works I couldn't get Selenium to work.

        wb.Visible = true;
        wb.Navigate(MainSite);
        {
            while (wb.Busy) { Thread.Sleep(100); }
            document = ((HTMLDocument)wb.Document);
            if (document.body.outerHTML.Contains("Logout")) { Loggedin = true; }
            if (!(document.body.outerHTML.Contains("Logout"))) { Loggedin = false; }
            if (Loggedin == false)
            {
                element = document.getElementById("Username");
                username = (HTMLInputElement)element;
                username.value = Username;
                username = null;
                element = document.getElementById("Passwd");
                password = (HTMLInputElement)element;
                password.value = Password;
                password = null;
                element = document.getElementById("Submit");
                Submit = (HTMLInputElement)element;
                Submit.click();
                Submit = null;
                while (wb.Busy) { Thread.Sleep(100); }
                SourceCode = document.body.outerHTML;
            }

        }