我正在尝试制作自动填充表单。我有一个我正在使用的vbscript,但是我无法转换它,因此我可以在Visual Studio中使用Visual Studio Web浏览器而不是IE。我遇到的主要问题是我无法访问页面上的项目(即VALUE,VALUE1等)有什么建议吗?
VBscript(工作)代码:
Set IE = CreateObject("InternetExplorer.Application")
intHighNumber = 193949
intLowNumber = 1
For i = 1 to 5
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
Next
s = cstr(intNumber)
set WshShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "INSERTURL"
IE.Visible = True
Wscript.Sleep 1000
IE.Document.All.Item("AVALUE").Value = "6"
IE.Document.All.Item("AVALUE1").Value = "2"
IE.Document.All.Item("AVALUE2").Value = "2000"
IE.Document.All.Item("AVALUE3").Value = s
IE.Document.All.Item("pass").Value = "nono2355"
IE.Document.All.Item("MaleBtn").Click
IE.Document.All.Item("passConfirm").Value = "nono2355"
IE.Navigate "AURL2&resize,128px"
WshShell.AppActivate "IE"
WshShell.SendKeys "{ENTER}"
VB(失败)代码:
Dim intHighNumber = 193949
Dim intLowNumber = 1
Dim intNumber As Integer
For i = 1 To 5
Randomize()
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd() + intLowNumber)
Next
WebBrowser1.Navigate("ANURL")
WebBrowser1.Visible = True
WebBrowser1.Document.All.Item("VALUE1").Value = "6"
WebBrowser1.Document.All.Item("VALUE2").Value = "2"
WebBrowser1.Document.All.Item("VALUE3").Value = "2000"
WebBrowser1.Document.All.Item("VALUE4").Value = intNumber.ToString
WebBrowser1.Document.All.Item("pass").Value = "nono2355"
WebBrowser1.Document.All.Item("MaleBtn").Click()
WebBrowser1.Document.All.Item("passConfirm").Value = "nono2355"
WebBrowser1.Navigate("ANURL2")
End Sub
答案 0 :(得分:0)
尝试在Navigate命令后添加DoEvents循环,以允许在设置值的代码运行之前加载文档。
WebBrowser1.Navigate("ANURL")
WebBrowser1.Visible = True
While WebBrowser1.Busy Or WebBrowser1.ReadyState <> 4
DoEvents
Wend
WebBrowser1.Document.All.Item("VALUE1").Value = "6"
...