vba - 无法填写某些日期输入来执行自定义搜索
问题描述
我正在尝试在 vba 中创建一个脚本,以根据我的偏好选择日期input date
,如03/11/2019
和output date
,如05/11/2019
两个字段check-in
和chek-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
脚本中存在一些故意延迟,我可以稍后定义任何定时循环。
如何在这些框中填写日期以执行自定义搜索?
解决方案
只需设置值属性
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
推荐阅读
- kubernetes - kube-apiserver 认证(未授权)
- jquery - 停止函数在 mouseleave 上运行
- arrays - 为什么 ASTextNode 不显示?
- android - 单击按钮启动和停止 HCE HostApduService - Android
- php - 什么是细枝扩展中的 basepath()
- python - 根据 fasta header 重命名文件
- ios - 在ios swift中使用alamofire请求超时错误1001?
- arrays - 为 r 中的索引对设置数组的子集
- c - 选择维度以在 C 中使用 FFTW 执行 FFT
- typo3 - Typoscript HMENU:在 2 级导航中获取 1 级标题