Javascript VBA未按元素ID填充

Javascript VBA未按元素ID填充,javascript,vba,internet-explorer,web-scraping,automation,Javascript,Vba,Internet Explorer,Web Scraping,Automation,我的密码有问题。 它在Sharepoint网站上运行良好——它是我练习和完成任务的虚拟网站;但在工作现场,它不起作用。 问题是,我有一封电子邮件,从中获取了所有元素,并试图在网站上自动填写,但什么也没发生 解析过程如下所示: Dim ie As InternetExplorerMedium Set ie = New InternetExplorerMedium ie.Visible = True ie.Navigate2 MarrPlazaWebForm Do DoEvents L

我的密码有问题。 它在Sharepoint网站上运行良好——它是我练习和完成任务的虚拟网站;但在工作现场,它不起作用。 问题是,我有一封电子邮件,从中获取了所有元素,并试图在网站上自动填写,但什么也没发生 解析过程如下所示:

Dim ie As InternetExplorerMedium

Set ie = New InternetExplorerMedium

ie.Visible = True
ie.Navigate2 MarrPlazaWebForm

Do
    DoEvents
Loop Until ie.Busy <> True Or ie.readyState = READYSTATE_COMPLETE

With ie
    .document.getElementById("label-for-pass_date_to").value = dateFrom
    .document.getElementById("label-for-pass_date_from").value = dateTo
    .document.getElementById("label-for-pass_username").value = guestName
    .document.getElementById("label-for-pass_description").value = requestorName
    .document.getElementById("pass_full_day").Checked = True

    Set elems = .document.getElementsByClassName("btn btn-primary")
    For Each e In elems
        If (e.getAttribute("type") = "submit") Then
            e.Click
            Exit For
        End If
    Next e
End With

On Error Resume Next
ie.Quit
<input type="text" id="label-for-pass_date_to" name="pass_date_from" class="form-control js-datepicker-from hasDatepicker" autocomplete="off" placeholder="From" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_date_from" name="pass_date_to" class="form-control js-datepicker-to hasDatepicker" autocomplete="off" placeholder="Untill" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_username" name="pass_username[0]" class="form-control" placeholder="Name of guest">
将ie设置为InternetExplorerMedia
设置ie=新的InternetExplorerMedium
可见=真实
例如:广场网络表单
做
多芬特
循环直到ie.Busy为真或ie.readyState=readyState\u完成
与ie
.document.getElementById(“label-for-pass\u date\u-to”).value=dateFrom
.document.getElementById(“通过日期的标签”).value=dateTo
.document.getElementById(“label-for-pass_-username”).value=guestName
.document.getElementById(“用于过程描述的标签”).value=requestorName
.document.getElementById(“通过全天”).Checked=True
Set elems=.document.getElementsByClassName(“btn btn primary”)
对于元素中的每个e
如果(例如getAttribute(“type”)=“submit”),则
e、 点击
退出
如果结束
下一个e
以
出错时继续下一步
即退出
该站点不按id获取元素,只将其保留为空

包含元素的站点代码如下所示:

Dim ie As InternetExplorerMedium

Set ie = New InternetExplorerMedium

ie.Visible = True
ie.Navigate2 MarrPlazaWebForm

Do
    DoEvents
Loop Until ie.Busy <> True Or ie.readyState = READYSTATE_COMPLETE

With ie
    .document.getElementById("label-for-pass_date_to").value = dateFrom
    .document.getElementById("label-for-pass_date_from").value = dateTo
    .document.getElementById("label-for-pass_username").value = guestName
    .document.getElementById("label-for-pass_description").value = requestorName
    .document.getElementById("pass_full_day").Checked = True

    Set elems = .document.getElementsByClassName("btn btn-primary")
    For Each e In elems
        If (e.getAttribute("type") = "submit") Then
            e.Click
            Exit For
        End If
    Next e
End With

On Error Resume Next
ie.Quit
<input type="text" id="label-for-pass_date_to" name="pass_date_from" class="form-control js-datepicker-from hasDatepicker" autocomplete="off" placeholder="From" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_date_from" name="pass_date_to" class="form-control js-datepicker-to hasDatepicker" autocomplete="off" placeholder="Untill" data-datepicker-disabled-date-before="true" data-mask="date">
<input type="text" id="label-for-pass_username" name="pass_username[0]" class="form-control" placeholder="Name of guest">

等等

我怀疑,也许工作站点是用JavaScript编写的,所有Id都不是我想要的
有什么建议吗?

我终于找到了问题所在

Dim ie作为InternetExplorerMedium-我使用了“InternetExplorer”,它开始正常工作

谢谢你的建议和回复,希望能派上用场
我还是不明白,为什么会这样-可能是因为我公司的一些安全策略

按F12,然后检查每个元素在将值填入文本框之前,请尝试添加断点或使用Debug.Print方法检查值(例如:dateFrom、dateTo和guestName)是否为空?此外,请尝试使用F12开发人员工具检查html资源,确保id属性正确,并验证文本框是否位于IFrame中?在VBA中,所有值都已填写,但在站点上-不。使用断点没有帮助-它只是告诉我,文本在那里,但不是。ID都是复制粘贴的,所以不应该有任何打字错误。唯一困扰我的是,在开发者模式(F12)下,只有当我按下文本输入字段时,网站才会开始调试。再次强调-这与此有关,但我不确定ID看起来很好。可能需要触发某种形式的事件才能接受值。使用F12开发人员工具检查IE浏览器中的html元素时,文本框是否位于IFrame中?是否有特殊的容器?