从Internet Explorer下拉列表中select选项
我正在打开一个网页并填写一些字段。 我设法填写文本框,但我有麻烦从下拉列表中select检查/select单选button的选项。
这是引用下拉列表的HTML代码:
下拉列表的HTML代码
这是一个单选button的代码 :单选button的HTML代码
这是我的代码到目前为止:
Sub w() ' ' w Macro ' ' Keyboard Shortcut: Ctrl+w ' 'pick ups cell b2 value Dim cellvalue As String cellvalue = ActiveSheet.Cells(1, 2) Dim HTMLDoc As HTMLDocument Dim oBrowser As InternetExplorer ''Sub Login_2_Website() Dim oHTML_Element As IHTMLElement Dim sURL As String On Error GoTo Err_Clear sURL = cellvalue ' Set oBrowser = New InternetExplorer oBrowser.Silent = True oBrowser.timeout = 60 oBrowser.navigate sURL oBrowser.Visible = True Do ' Wait till the Browser is loaded Loop Until oBrowser.readyState = READYSTATE_COMPLETE Set HTMLDoc = oBrowser.document 'fill email response address HTMLDoc.all.emailAddresses.Value = ActiveSheet.Cells(5, 3) 'fill shipment reference number HTMLDoc.all.filingRefNumber.Value = ActiveSheet.Cells(5, 7) 'fill dropbox option 'NOT WORKING If Not VBA.IsNull(ie.document.getElementById("select2-drop-mask")) Then Dim htmlSelect Set htmlSelect = ie.document.getElementById("select2-drop-mask") htmlSelect.Value = 4 - POSTDEPARTURE Else MsgBox "Element 'select2-drop-mask' was not found", vbExclamation End If 'SELECT RADIO BUTTON ' NOT WORKING ie.document.getElementsByName("shipmentInfo.routedExpTransactionInd.stringFiEld").Item(1).Checked = True For Each oHTML_Element In HTMLDoc.getElementsByTagName("Login") If oHTML_Element.Type = "Login" Then oHTML_Element.Click: Exit For Next ' oBrowser.Refresh ' Refresh If Needed Err_Clear: If Err <> 0 Then 'Debug.Assert Err = 0 Err.Clear Resume Next End If End Sub
关于你的名单/下拉,我认为有两个可能的解决scheme。
-
改成
htmlSelect.Value =“4 – POSTDEPARTURE”
-
请参阅索引值。 也就是说,如果它是下拉菜单中的第一项,则是项目(0)。
htmlSelect.item(0).selected = “真”
对于您的单选button,用引号将“true”换行。 你也需要遍历所有具有该特定名称的元素(getElementbyID只返回1个项目,但getElementsByName可以指向多个元素)。
例如
dim objects dim obj set objects=document.getElementsByName("shipmentInfo.routedExpTransactionInd.stringFiEld") for each obj in objects obj.item(0).checked=True next
或尝试:
Set ieRadio = IE.Document.all ieRadio.Item("shipmentInfo.routedExpTransactionInd.stringFiEld")(1).Checked = True
- 哪个.dll包含HTMLElement类?
- Excel VBA – 从网页中提取数据
- 当button没有“名称”关联时,使用Excel VBA单击Internet Explorer中的button
- 如何用VBA Excel Internet Explorer按第二个button
- 使用VBA在Microsoft 365电子邮件中按“新邮件”button
- IE11框架通知栏保存button
- Excel VBA和IE 11 – 在下拉菜单中select值后无法刷新页面
- 从Internet Explorer中导出HTML数据以实现卓越?
- closures选项,从网站在Internet Explorer中打开xls文件?