[VBA控制IE(html)]Select下拉列表内容&自动更改错误

[VBA control IE(html)]Select drop-list contents & automatically change error

-请查看第一个 GIF 文件。

[GIF说明][1]

https://i.stack.imgur.com/qwEed.gif

我正在尝试使用 VBA 让网络自动控制宏。在制作过程中,有很多块点。但多亏了你的帮助,我才得以解决。

但是脚本中出现了大问题。

如果我选择 3(领域、产品设计、技术中心)数据,“验证者”、“经理”值会自动选择。

但是没有变化,因为我选择了3个数据。然后当我用鼠标点击时,那个时候“Validator”、“Manager”的值被改变了。

请告诉我问题是什么或者我该如何改进。 提前谢谢你。

如果您需要更多信息,请告诉我您需要什么。

Sub a()

Dim IE_ctrl As InternetExplorerMedium
Dim HTMLDoc As IHTMLDocument
Dim input_Data As IHTMLElement
Dim url As String
Dim I, J, JJ As Integer

J = 2

'URL Setting'
url = "https://apps.faurecia/sites/fcm_km_testing/Site%20pages/Homepage.aspx"

'Explorer Setting'
Set IE_ctrl = New InternetExplorerMedium
IE_ctrl.Silent = True
IE_ctrl.Visible = True
IE_ctrl.navigate url

Wait_Browser IE_ctrl

Set HTMLDoc = IE_ctrl.document

'Click - Create a new Test report'
For Each input_Data In HTMLDoc.getElementsByTagName("img")
    Debug.Print input_Data.alt
    If input_Data.alt = "IcnCreate.png" Then
    input_Data.Click
    Exit For
    End If
Next
'END'

Wait_Browser IE_ctrl

'Insert - Insert LTI number'
For Each input_Data In HTMLDoc.getElementsByTagName("input")
    Debug.Print input_Data.ID
    If input_Data.ID = "txtLTINumber" Then
    input_Data.Value = Cells(J, 1)
    End If
Next
'END'

Wait_Browser IE_ctrl

'Click - LTI loading click'
For Each input_Data In HTMLDoc.getElementsByTagName("button")
    Debug.Print input_Data.ID
    If input_Data.ID = "btnFindLTI" Then
    input_Data.Click
    Exit For
    End If
Next
'END'

Wait_Browser IE_ctrl

For Each input_Data In HTMLDoc.getElementsByTagName("select")(0).getElementsByTagName("option")
    Debug.Print input_Data.Value
    If input_Data.Value = "3702e9f0-6271-42ff-b5b2-04ef121b0f69" Then
    input_Data.Click
    input_Data.Selected = True
    Exit For
    End If
Next


For Each input_Data In HTMLDoc.getElementsByTagName("select")(0).getElementsByTagName("option")
    Debug.Print input_Data.innerText
    If input_Data.innerText = Cells(J, 2) Then
'    input_Data.Click
    input_Data.Value = Cells(J, 2)
'    input_Data.Focus
    input_Data.Selected = True
'    input_Data.FireEvent ("onchange")
    Exit For
    End If
Next

    For Each input_Data In HTMLDoc.getElementsByTagName("select")(1).getElementsByTagName("option")
    Debug.Print input_Data.innerText
    If input_Data.innerText = Cells(J, 3) Then
    input_Data.Focus
    input_Data.Selected = True
    input_Data.FireEvent ("onchange")
    Exit For
    End If
Next

For Each input_Data In HTMLDoc.getElementsByTagName("select")(2).getElementsByTagName("option")
    Debug.Print input_Data.innerText
    If input_Data.innerText = Cells(J, 4) Then
    input_Data.Focus
    input_Data.Selected = True
    input_Data.FireEvent ("onchange")
    Exit For
    End If
Next

For Each input_Data In HTMLDoc.getElementsByClassName("sp-peoplepicker-topLevel customPeoplePicker")(3).getElementsByTagName("input")
    Debug.Print input_Data.className
    If input_Data.className = "sp-peoplepicker-editorInput" Then
    input_Data.Value = Cells(J, 5)
    Exit For
    End If
Next

For Each input_Data In HTMLDoc.getElementsByTagName("input")
    Debug.Print input_Data.ID
    If input_Data.ID = "btnSave" Then
    input_Data.Click
    Exit For
    End If
Next

End Sub

[选择保管箱 lsit][1]

https://i.stack.imgur.com/uLb91.png

[验证器 - 在点击下拉列表之前][2]

https://i.stack.imgur.com/y2CtW.png

[验证器 - 单击下拉列表后][3]

https://i.stack.imgur.com/Hs32j.png

我认为“Validator”和“Manager”的值不会改变,因为“Domain”后面的点击功能没有被激发。

设置<select>的值时请尝试使用Click使脚本运行在后台运行。

由于我无法访问该网站,因此无法进行全面测试。我只能猜测示例代码是这样的,您可以根据自己的实际情况编辑代码:

Set doc = ieA.Document
Set selectElement = doc.getElementById("txtDomain")  'get "Domain" element
selectElement.Click
selectElement.selectedIndex = 3  'set the option value using index