首页 > 解决方案 > 填写网络表单时,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 &amp;&amp; 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

标签: vbainternet-explorerwebforms

解决方案


试着把'.' 像下面这样的类名之间的工作在我身边。

 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

输出:

在此处输入图像描述


推荐阅读