vba - 填写网络表单时,VBA 对象不支持属性或方法
问题描述
我正在尝试使用Excel VBA
来填充 aweb form
然后抓取一些数据。
我被困在如何输入我想要搜索的值上。
在源代码中,没有我可以使用的 id 或 name。
我尝试了一个类名,但它不起作用。
" Source code:
<input type="text" style="height: 28px; width: 170px; padding-left: 5px;" ng-model="model.FieldValue" placeholder="Enter a Value" ng-show="model.searchOptions.length && model.searchOptions != 'SQE Quote Id'" class="ng-pristine ng-valid ng-touched">
Sub Macro1()
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim html As HTMLDocument
Set IE = New InternetExplorerMedium
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "xxxx"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do While IE.ReadyState = 4: DoEvents: Loop 'Do While
Do Until IE.ReadyState = 4: DoEvents: Loop 'Do Until
'
Set html = IE.Document
IE.Document.getElementById("searchOptions").Click (2)
IE.Document.getElementById("searchOptions").Value = "Access Qref"
IE.Document.getelemenetbyclassname("ng-pristine ng-valid ng-touched").Value = "00000"
'
End Sub
解决方案
试着把'.' 像下面这样的类名之间的工作在我身边。
IE.Document.querySelector("input.ng-pristine.ng-valid.ng-touched").Value = "00000"
修改示例:
Sub Macro1()
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim html As HTMLDocument
Set IE = New InternetExplorerMedium
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "D:\Backup20190913\tests\353.html"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
Do While IE.ReadyState = 4: DoEvents: Loop 'Do While
Do Until IE.ReadyState = 4: DoEvents: Loop 'Do Until
Set html = IE.Document
IE.Document.querySelector("input.ng-pristine.ng-valid.ng-touched").Value = "00000"
End Sub
输出:
推荐阅读
- html - 为什么字体粗细属性 (CSS) 在某些元素中不起作用?
- python - 从锚点中提取href属性url
- c++ - 电源模板编码
- python - 如何读取大量 csv 文件并计算每个文件的箱线图统计信息?
- xml - 对于 XML 中的每个节点未按预期工作
- python - 更快地实现像素映射
- c++ - List 上的冒泡排序——在计算上花费了太多时间
- python - 如何在包依赖项> 500MB的AWS lambda上运行python代码?
- android - 如何在 android Studio 上直接向 TFVC 添加解决方案?
- react-native - react-devtools中的“连接到react ....”,当我想连接react native android模拟器时