html - [VBA control IE(html)]选择下拉列表内容&自动更改错误
问题描述
- 请查看第一个 GIF 文件。
[GIF解说][1]
https://i.stack.imgur.com/qwEed.gif
我正在尝试使用 VBA 使 web 自动控制宏。在制作过程中,有很多阻塞点。但是由于您的帮助,我可以解决它。
但是在脚本中出现了很大的问题。
- 解释:
如果我选择 3(域、产品设计、技术中心)数据,则自动选择“验证器”、“经理”值。
但是没有变化,因为我选择了 3 个数据。然后当我使用鼠标单击时,当时“验证器”、“管理器”的值发生了变化。
请告诉我有什么问题或我该如何改进。先感谢您。
如果您需要更多信息,请告诉我您需要什么。
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]
解决方案
我认为“Validator”和“Manager”的值不会改变,因为“Domain”后面的点击功能没有被触发。
请尝试Click
在设置值时使用<select>
,使脚本在后台运行。
由于我无法访问该网站,因此无法进行完整测试。我只能猜测示例代码是这样的,你可以根据你的实际情况编辑代码:
Set doc = ieA.Document
Set selectElement = doc.getElementById("txtDomain") 'get "Domain" element
selectElement.Click
selectElement.selectedIndex = 3 'set the option value using index
推荐阅读
- android - Android 不会像 #c01c2112 那样打印 ARGB 颜色
- generics - 如何在 rust 中声明可比较的东西的通用向量
- java - 当我的列表不为空时,为什么我会得到 java.lang.NullPointerException?
- javascript - Phaser 3:一些动画突然停止播放
- hibernate - 休眠排序规则配置
- sql-server - 加入内部视图非常慢
- c# - WPF - 将矢量图像绑定到增强的工具提示
- python-3.x - 如何检索在 AWS Lambda 函数上定义的环境变量
- spring-boot - 第一次调用 ZuulException (SendErrorFilter)
- java - 如何实现构造函数/析构函数对称,对于 Java