使用VBA在网页上绕过日期选择器

问题描述 投票:0回答:1

我是一个完整的初学者,请多多包涵。

我正在使用VBA从我们的名册Web应用中获取excel报告,并将其转换为ics日历事件。我现在有一个手动的逐步过程,因此我想通过使用vba进行自动化以登录并导出花名册。

我被困的地方:我可以登录并通过getElementId更改一些参数并更改值,但是我想更改由日期选择器完成的导出日期。我无法在显示字段中单击并输入文本,我只能使用日期选择器。我一直在寻找DOM,但是找不到可以更改其值的Elements。

https://imgur.com/XDNI2wo

'Select Show Hours
IE.document.GetElementById("ContentPlaceHolder1_Select_ShowHours").Checked = True

'Select Staff as "Me Only"
IE.document.GetElementById("ContentPlaceHolder1_Select_Staff").Value = "999"

'Run Report
IE.document.GetElementById("ContentPlaceHolder1_btnReport").Click
Do Until Not IE.Busy And IE.readyState = 4
    DoEvents
Loop
html excel vba internet-explorer browser-automation
1个回答
0
投票

从屏幕快照中,我们可以看到使用readonly属性的Date文本框,在使用VBA脚本查找此元素并在其中写入值之前,我们需要删除readonly属性。然后,使用Application.SendKeys方法将值发送到Date文本框。更多详细信息,请参考以下示例代码:

    Set startDateText = IE.document.getElementbyId("startdate")

    'remove the readonly attribute.
    startDateText.removeAttribute ("readonly")
    startDateText.Focus

    'using sendkeys method to enter the date.         
    Application.SendKeys "10/21/2019", True

    'Waiting the date value enters (3 second) 
    Application.Wait (Now + TimeValue("0:00:03"))

    Set endDateText = IE.document.getElementbyId("enddate")
    endDateText.Focus        
    Application.SendKeys "10/28/2019", True 
    Application.Wait (Now + TimeValue("0:00:03"))

    IE.document.all("startdate").Click

HTML资源如下:

Start Date: <input type="text" id="startdate" name="startdate" value="" readOnly = "readonly" class="form-control" size="30">   
End Date: <input type="text" id="enddate" name="enddate" value="" class="form-control" size="30">
© www.soinside.com 2019 - 2024. All rights reserved.