【问题标题】:[VBA control IE(html)]Select drop-list contents & automatically change error[VBA control IE(html)]选择下拉列表内容&自动更改错误
【发布时间】:2021-04-20 05:11:31
【问题描述】:

-请查看第一个 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]

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

【问题讨论】:

  • 如果将其简化为一个问题(稍后询问任何后续要求)会更容易。这看起来像一个专有站点(或至少基于登录),这将使我们难以/不可能进行测试。您可以为我们找到一种方法来 1)复制问题 2)从您问题中的信息中充分理解问题,以提供有用的建议。从问题中充分理解它意味着包括相关的html,解释你研究过的内容等......
  • 您能否澄清以 If I choose 3 ........结尾的行 "Manager" value was changed.
  • 对不起,我的解释不够。如果你看到 GIF?它更容易解释。 (1) 自动选择(使用 VBA)3 个数据(“领域”、“产品设计”、“技术中心”:参见i.stack.imgur.com/uLb91.png)。 (2)最初在(1)过程之后,2个结果(“Validators”,“Manager”)将自动更改。(i.stack.imgur.com/y2CtW.png)当我使用鼠标单击时,2个结果被更改。但我使用 VBA,2 结果没有改变。你还好吗?
  • 嗨@ahnsanghyuk 这个问题怎么样?我下面的回答对解决这个问题有帮助吗?如果是这样,你可以参考this,它可以帮助其他社区成员将来解决类似的问题。感谢您的理解。

标签: html vba internet-explorer


【解决方案1】:

我认为“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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-20
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多