1

我正在尝试在 vba 中创建一个脚本,以根据我的偏好选择日期input date,如03/11/2019output date,如05/11/2019两个字段check-inchek-out。到目前为止,我编写的宏可以单击这些字段,但不能用上述日期填写输入。

网站地址

我试过了:

Sub FillInTheForm()
    Dim IE As New InternetExplorer, HTML As HTMLDocument
    Dim post As Object, elem As Object, guest As Object
    Dim findbtn As Object, URL$

    URL = "https://www.discoverqatar.qa/"

    With IE
        .Visible = True
        .navigate URL
        While .Busy = True Or .readyState < 4: DoEvents: Wend
        Application.Wait Now + TimeValue("00:00:05")
        Set post = .document.querySelector("[class='rsp_s_checkindate_input'] > #lpPannel_txtFromDate")
        post.Focus
        post.Click

        Application.Wait Now + TimeValue("00:00:05")
        Set elem = .document.querySelector("[class='rsp_s_checkoutdate_input'] > #lpPannel_txtToDate")
        elem.Focus
        elem.Click

        Application.Wait Now + TimeValue("00:00:05")
        Set guest = .document.querySelector("#lblPaxInfo")
        guest.Focus
        guest.Click

        Application.Wait Now + TimeValue("00:00:05")
        Set findbtn = .document.querySelector("input#btnSearch")
        findbtn.Focus
        findbtn.Click
    End With
'    IE.Quit
End Sub

脚本中存在一些故意延迟,我可以稍后定义任何定时循环。

如何在这些框中填写日期以执行自定义搜索?

4

1 回答 1

2

只需设置值属性

Option Explicit
Public Sub SetDates()
    Dim ie As InternetExplorer

    Set ie = New InternetExplorer

    With ie
        .Visible = True
        .Navigate2 "https://www.discoverqatar.qa/"

        While .Busy Or .readyState <> 4: DoEvents: Wend

        With .document
            .querySelector("#lpPannel_txtFromDate").Value = "03/11/2019"
            .querySelector("#lpPannel_txtToDate").Value = "05/11/2019"
            .querySelector("#btnSearch").Click
            Stop
        End With
    End With
End Sub
于 2019-10-30T23:20:51.737 回答