我试图在使用自动化从Microsoft Access 2003,以控制Internet Explorer 9通过数据库中的数据来完成的一种形式。
输入,其中验证数据,并且使保存按钮可见浏览器触发一个事件。 如果我使用的SendKeys触发事件; 然而,我发现的SendKeys是非常不可靠的。 如果我改变元素的值,然后使用.fireevent(“平变化”),没有任何反应 - 即使不是一个错误。
我的问题是,我怎么触发事件。 或者说,我怎么能找出的JavaScript运行。 是否有插件的IE浏览器调试类型它会告诉我什么事件被触发? 如果是的话,我能运行该脚本自己?
我的代码如下。
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
IE.Navigate "https://extranet.website.com/Planning/Edition/Periodic?language=en"
Do While IE.ReadyState <> 4 Or IE.Busy = True
DoEvents
Loop
'log in
If IE.Document.Title = "website- access" Then
IE.Document.getElementById("login_uid").Value = "username"
IE.Document.getElementById("login_pwd").Value = "password"
IE.Document.all("ButSubmit").Click
Do While IE.ReadyState <> 4 Or IE.Busy = True
DoEvents
Loop
End If
Do While Not RstAvailability.EOF
StartDate = RstAvailability!AvailDate
IE.Document.getElementById("periodStart").Value = Format(StartDate, "dd mmm yy")
IE.Document.getElementById("periodEnd").Value = Format(StartDate, "dd mmm yy")
Set LinkCollection = IE.Document.GetElementsByTagName("A")
For Each link In LinkCollection
If link.innertext = "Add" Then
link.Click
Exit For
End If
Next
Do While IE.ReadyState <> 4 Or IE.Busy = True
DoEvents
Loop
Set objRows = IE.Document.GetElementsByTagName("tr")
If RstAvailability!RoomType = "DTW" Then
n = 0
While n < objRows.Length
If Trim(objRows(n).Cells(0).innertext) = "Single Room" Then
For i = 1 To 7
'objRows(n).FireEvent ("onchange")
'objRows(n).Cells(i).GetElementsByTagName("input")(0).Focus
'SendKeys Format(RstAvailability!roomcount - RstAvailability!RoomsSold, "0") & "{TAB}"
objRows(n).Cells(i).GetElementsByTagName("input")(0).Value = Format(RstAvailability!roomcount - RstAvailability!RoomsSold, "0")
objRows(n).Cells(i).GetElementsByTagName("input")(0).fireevent ("onchange")
Do While IE.ReadyState <> 4 Or IE.Busy = True
DoEvents
Loop
Next i
End If
n = n + 1
Wend
End If
Set objButtons = IE.Document.getelementsbyname("savePlanning")
objButtons(0).Click
Do While IE.ReadyState <> 4 Or IE.Busy = True
DoEvents
Loop
newtime = Now + TimeValue("0:00:10")
Do While True
If Now > newtime Then Exit Do
Loop
RstAvailability.MoveNext
Loop
输入字段的HTML是:
<tr class="first" roomId="30494" articleId="0" type="Availability" readonly="False">
<div>
<span class="roomName">
Single Room
</span>
</div>
<span class="data">
<input id="Availabilities" name="Availabilities" type="text" value="" />
</span>
<span class="data">
<input id="Availabilities" name="Availabilities" type="text" value="" />
</span>
谢谢!