嗨,我正在尝试使用 VB.NET 单击网站上的按钮
我在 .AHK 中使用的命令是
Pwb.document.getElementsByTagName("IMG")[7].click
按钮/Img HTML 如下。
<img width="34" height="34" style="cursor: pointer;" onclick="doSubmit()" alt="" src="../../images/SC5Login07.jpg" border="0" complete="complete"/>
我注意到它在单击时正在运行一些 javascript。也就是下面
function doSubmit() {
//Submit the form
if (document.getElementById("txtDBName").value == "") {
//Login security modifications - End
alert('You must select a Database');
}
else {
if (document.getElementById("txtUserName").value == "") {
alert('Please enter your Tesseract user id and password');
}
else {
//Set txtformEvent
document.getElementById("txtFormEvent").value = "onSubmit";
//Submit the form
document.getElementById("frmLoginLaunch").submit();
}
}
}
现在我知道有一个 GetElementById 但由于缺少 ID 我无法让它工作。我希望它会像在 AHK 中一样简单,但看起来并非如此。
基本上有没有办法调用这个 dosubmit() 函数或模拟点击图像?
希望有人可以帮助谢谢
谢谢大家,这是我现在的登录代码
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://caan/SC5/SC_Login/aspx/login_launch.aspx?SOURCE=ESOLBRANCHLIVE")
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
WebBrowser1.Document.GetElementById("txtUserName").SetAttribute("value", "kieranw")
WebBrowser1.Document.GetElementById("txtPassword").SetAttribute("value", "kieranw")
Dim allImgTags As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
If allImgTags IsNot Nothing Then
For Each img As HtmlElement In allImgTags
If img.GetAttribute("src").Contains("/images/SC5Login07.jpg") Then
img.InvokeMember("Click")
Exit For
End If
Next img
End If
End Sub
结束类