0

我需要为朋友做一个自动登录工作,但我无法完成,我无法使用文本框的 id 插入文本,

调试器说:“对象引用未设置为对象的实例”

你能告诉我我做错了什么或如何解决它吗?

在此处输入图像描述

这是表格:

Public Class Form1

    'Dim WebBrowser1 As New WebBrowser
    Dim elm
    Public Sub searchbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchbutton.Click

        'WebBrowser1.Document.GetElementById("id_username").SetAttribute("value", "yourusernamehere")
        WebBrowser1.Document.GetElementById("id_username").InnerText = "yourusernamehere"

    End Sub

    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'WebBrowser1.Navigate("http://www.planetromeo.com/")
        WebBrowser1.Navigate("http://www.planetromeo.com/main/login.php")

    End Sub

End Class

这是 http://site.../main/login.php 源:

<body class="pgLe" id="pgLeLo">
<div id="head"> <h1>Inicio de sesión</h1></div>
<div id="loginWindow">
  <form method="post" action="https://www.planetromeo.com" name="login" target="_top" onsubmit="return submithandler()">
  <input type="hidden" name="PHPSESSID" value="wLzgSbXmdg7Goi1VYDiaXc4Hs4PV71gs" />  <input type="hidden" name="salt" id="id_salt" value="8547695" />
  <input type="hidden" name="resX" id="id_resX" value="" />
  <input type="hidden" name="resY" id="id_resY" value="" />
  <input type="hidden" name="secure" id="id_secure" value="" />
  <input type="hidden" name="initCallSec" id="id_initCallSec" value="0" />

  <div id="loginBox">
    <div class="spacer" style="height:9px;padding:0"></div>
    <div class="inputBox">
      <input type="text" name="username" value="" id="id_username" size="12" maxlength="70" class="textbox" onchange="document.forms['login'].erinnern.checked=false" /><br />
      <label for="id_username">Nombre del perfil</label>
    </div>
    <div class="inputBox">
      <input type="password" name="passwort" value="" id="id_password" size="12" maxlength="20" class="textbox" onchange="document.forms['login'].secure.value=''" /><br />
      <label for="id_password">Contraseña</label>
    </div>
    <div id="statusBox">
      <select name="status" id="status" class="textbox">
                <option value="-1">Como última vez</option>
        <option value="2">Charlar</option><option value="6">Amigos</option><option value="1">Nada</option><option value="3">Relación</option><option value="4">Cita</option><option value="7">Sexo</option><option value="8">Ocupado</option><option value="0">Ausente</option><option value="5">Invisible&nbsp;(Plus)</option>      </select>
    </div>
    <div class="checkerBox">
      <input type="checkbox" name="erinnern" value="1" id="id_erinnern" class="checkbox" /><label for="id_erinnern"><a href="../service/kontakthilfe/keyword_suche.php?helpid=166" onclick="return openUrl(this.href)">Recordar</a></label>
    </div>
    <div class="checkerBox">
      <input type="checkbox" name="jugendfrei" value="1" id="jugendfrei" class="checkbox" /><label for="jugendfrei"><a href="../service/kontakthilfe/keyword_suche.php?helpid=167" onclick="return openUrl(this.href)">Sin XXX</a></label>
    </div>
    <div>
      <input type="submit" value="Entrar" class="button" />
    </div>
  </div>
  <div id="infoBox">
    <a href="https://www.planetromeo.com//00000000000000000000000000000000/service/login/" target="mitte">¿Olvidaste tu contraseña?</a><br />
          <a href="https://www.planetromeo.com" target="_top">Activar SSL</a>
      </div>
  </form>
</div>

这是 http://site...com 来源:

<!DOCTYPE html>
<html>
<head>
<meta name="apple-itunes-app" content="app-id=404386888" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><title>PlanetRomeo</title>
<script type="text/javascript">

function switchLanguage(lang) {
  var frm = frames['oben'].document.forms['jump'];
  frm.lang.value = lang;
  frm.submit();
  return false;
}

</script>

  <meta name="keywords" content="planetromeo,romeo,community,chat,men,kontakte" />
  <meta name="description" content="Online community and dating service for men. Free registration and search." />
      <link rel="apple-touch-icon-precomposed" href="/v1/img/touch-icon.png" />
</head>



<frameset cols="*,796,*" framespacing="0" border="0" frameborder="0">
<frame name="links" src="/00000000000000000000000000000000/main/left.php" scrolling="no" noresize="noresize" />
<frameset rows="58,*" framespacing="0" border="0" frameborder="0">
<frame name="oben" src="/00000000000000000000000000000000/main/top.php" marginwidth="0" marginheight="0" scrolling="no" noresize="noresize" />
<frameset cols="116,680" framespacing="0" border="0" frameborder="0">
  <frame name="persoenliches" src="/main/login.php" marginwidth="0" marginheight="0" scrolling="no" noresize="noresize" />
  <frame name="mitte" src="/00000000000000000000000000000000/main/index.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
</frameset>
</frameset>
  <frame name="heartbeat" src="/00000000000000000000000000000000/main/right.php" scrolling="no" noresize="noresize" />

  <noframes>
  <h1></h1>
  <p>Online community and dating service for men. Free registration and search.</p>
  <p>Sorry, frame support needed!</p>
  <a href="/00000000000000000000000000000000/main/top.php">Menu</a><br />
  <a href="/00000000000000000000000000000000/main/index.php">Main Page</a>
  </noframes>

</frameset>


</html>
4

1 回答 1

1

本文建议使用不同的语法...

http://vbcity.com/blogs/jatkinson/archive/2009/12/12/programmatically-entering-and-data-using-the-webbrowser-control.aspx

例如

Dim usernameTextBox As HtmlElement = Me.mainWebBrowser.Document.All.Item("Email")
usernameTextBox.InnerText = "james.t.atkinson"

但对于按钮

Me.mainWebBrowser.Document.GetElementById("signIn").InvokeMember("click")

于 2012-11-30T20:02:19.780 回答