-1

我正在尝试制作自动表格填充物。我有一个我正在使用的 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
4

1 回答 1

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"
...
于 2013-06-09T15:30:20.113 回答