以编程方式登录的问题 [英] Problem with login programmatically

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

问题描述

嗨 我想以编程方式登录我的资源,我使用了这段代码,但是我处理了这个错误
对象引用未设置为对象的实例"

这是我的密码

Hi I want to login to my resorces programmatically, I used this code but I deal with this error
"Object reference not set to an instance of an object"

This is my codes

Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    STAOparation()
End Sub

Public Sub STAOparation()

    Dim WB As System.Windows.Forms.WebBrowser

    WB.Navigate("My_URL_LoginPage")
    Dim usernameTextBox As System.Windows.Forms.HtmlElement = WB.Document.All.Item(txtClientUsername)
    usernameTextBox.InnerText ="MY_UserName"

    Dim passwordTextBox As System.Windows.Forms.HtmlElement = WB.Document.All.Item(txtClientPassword)
    passwordTextBox.InnerText = "My_Pass";
    WB.Document.GetElementById(cmdClientLogin).InvokeMember(click)

End Sub




特定错误发生在WB.Navigate("My_URL_LoginPage")行上,我不知道如何解决
[/Edit]




the specefic error occured on WB.Navigate("My_URL_LoginPage") line and i dont know how do solve it
[/Edit]

推荐答案

我看到您尚未创建Web浏览器控件的实例.您仅声明了变量WB,因此将其初始化为null.修复该错误,该错误将消失.

此致

Manfred
I see you haven''t created an instance of the web browser control. You only declared the variable WB and it is thus initialized to null. Fix that and that error will be gone.

Regards,

Manfred


当您尝试使用空对象的属性时,会发生此错误.

更多详细信息:此处 [
This error happens when you try to use a property of an object that is null.

More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


这篇关于以编程方式登录的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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