2017-03-05 5 views
0

誰かをサイトに自動ログインする機能を作成しようとしています。C#IDなしでサイトにログイン

別のフォームから文字列をインポートするため、frm.Loginとfrm.Passwordがあります。他のフォームは、資格情報を入力する場所です。

免責事項: 私はこのサイトにアクセスできません!

HTMLコード

<input type="email" required="" size="21" name="email"> //email 
<input type="password" required="" name="password" size="21"> //password 
<input type="submit" name="submit" value="Sign in"> //button to sign in. 

私の試み

Form3 frm = new Form3(); 
frm.ShowDialog(); 
webBrowser1.Navigate("examplesite.php"); 

webBrowser1.Document.GetElementsByTagName("input") 
      .GetElementsByName("email")[0] 
      .SetAttribute("Value", frm.Login); 

webBrowser1.Document.GetElementsByTagName("input") 
      .GetElementsByName("password")[0] 
      .SetAttribute("Value", frm.Password); 

ClickButton("submit"); 

ClickButtonのコード

public void ClickButton(string type) 
{ 
    var button = webBrowser1.Document.GetElementsByTagName("submit") 
      .Cast<HtmlElement>() 
      .FirstOrDefault(m => m.GetAttribute("type") == type); 
    if (button != null) 
     button.InvokeMember("click"); 
} 

Error: An unhandled exception of type 'System.NullReferenceException' occurred in Test.exe Additional information: Object reference not set to an instance of an object.

Line that gives error: webBrowser1.Document.GetElementsByTagName("input").GetElementsByName("email")[0].SetAttribute("Value", frm.Login);

+2

あなたの質問はありますか? – SLaks

+0

winformsアプリケーションの文字列をサイトのログインとパスワードのテキストボックスに渡すには... –

+1

サイトに移動すると、サイトが完全に読み込まれるまで待つ必要があります。今すぐ失敗するかもしれないテキストボックスの値を設定します。エラーはまさに私が考えるものです。 webBrowserには、ロードされたドキュメントのイベントがあります。 – urlreader

答えて

0

ボタンをクリックするコード。 「ログイン」値が表示され、クリックされます

foreach (HtmlElement el in elCol) 
       { 
        if (el.GetAttribute("value").Equals("Sign in")) 
        { 
         el.InvokeMember("click"); 
        } 
       } 
関連する問題