GetElementbyID" Exception unhandled" [英] GetElementbyID "Exception unhandled"

查看:70
本文介绍了GetElementbyID" Exception unhandled"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


我正在为论坛制作登录应用程序,我的表单的目的是直接从应用程序登录论坛而不使用webbrowser。


我在表单中添加了一个隐藏的webbrowser,一个标签和2个文本框,用作用户名框,密码字段和"登录"按钮。


这些对象与具有以下scirpt的页面交互


WebBrowser1.Document.GetElementById(userbox).InnerText = username

WebBrowser1.Document.GetElementById (keybox).InnerText =密码

WebBrowser1.Document.GetElementById(loginbtn).InvokeMember(" click")


哪个不会导致Visual错误Studio,但是当我点击Label登录时,我得到一个"Exception unhandled"在我的脚本表中弹出。


它说


" System.NullReferenceException:'对象引用未设置为对象的实例。'



System.Windows.Forms.HtmlDocument.GetElementById(...)返回Nothing。"




异常详情:


System.NullReferenceException发生

  HResult = 0x80004003

  Message =对象引用未设置为对象的实例。

 来源= Epepistheway

  StackTrace:

   在Epepistheway.Form1.Label5_Click(对象发件人,EventArgs e)在C:\ Users \User \ AppData \ Local \ Temporary Projects \ Epepistheway \Form1.vb:第17行

   在System.Windows.Forms.Control.OnClick(EventArgs e)

   在System.Windows.Forms.Control.WmMouseUp(消息& m,MouseButtons按钮,Int32点击)

    at System.Windows.Forms.Control.WndProc(Message& m)

    at System.Windows.Forms.Label.WndProc(Message& m)

    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)

  ;   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)

    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)

    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()

    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()

    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String [] commandLine)

   在Epepistheway.My.MyApplication.Main(String [] Args)in:第81行


我如何修复这个?请帮忙。谢谢你的建议。

解决方案

嗨朋友,


这个问题与Winform有关,我将把它移到相应的论坛,以便您快速得到答案。




祝你好运,


陈伟伟


Hello everyone.

I am making a login App for my forum, the purpose of my form is to login to the forum directly from the app without use of webbrowser.

I added an hidden webbrowser in the form, a label and 2 text boxed, which works as Username Box, Password Field and ''login'' button.

Those objects interact with the page with the following scirpt

WebBrowser1.Document.GetElementById(userbox).InnerText = username
WebBrowser1.Document.GetElementById(keybox).InnerText = password
WebBrowser1.Document.GetElementById(loginbtn).InvokeMember("click")

Which doesn't result wrong to Visual Studio, but when I click the Label to login, I get a "Exception unhandled" popup in my script table.

It says

"System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing."

Exception details:

System.NullReferenceException occurred
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Epepistheway
  StackTrace:
   at Epepistheway.Form1.Label5_Click(Object sender, EventArgs e) in C:\Users\User\AppData\Local\Temporary Projects\Epepistheway\Form1.vb:line 17
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Label.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at Epepistheway.My.MyApplication.Main(String[] Args) in :line 81

How do I fix this? Please help. Thanks in advice.

解决方案

Hi friend,

This issue is more related to Winform, I'll move it to corresponding forum for you to get a quick answer.

Best regards,

Fletch


这篇关于GetElementbyID" Exception unhandled"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆