0

Using selenium VBA, I am uploading some data and there is a date which I need to insert using datepicker. Here's the html of the webpage that has the datepicker https://pastebin.com/yqf8H36k

I tried to use SendKeys to send the date directly but the datepicker popup appeared and nothing entered.

.FindElementById("date").SendKeys wsUpload.Range("B5").Value
.FindElementById("date").Click
Debug.Print .FindElementByXPath("//div[@role='period']").Attribute("innerHTML")
.FindElementByXPath("//div[@role='period']").Click

Any ideas...?

YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
  • https://getdatepicker.com/4/ , https://stackoverflow.com/a/40367539, https://stackoverflow.com/a/59761118 – QHarr Dec 10 '20 at 17:53
  • ^^ you have a bootstrap datepicker like link 1 in comment above. The second two links show how to "cheat" programmatically interact with it and inject your date. The format for the jquery part depends on what the format is for your datepicker. – QHarr Dec 10 '20 at 17:54
  • I have no great idea about bootstrap. How can I get the link to the datepicker? – YasserKhalil Dec 10 '20 at 17:58
  • 1
    I put a link above you can use for demo (just scroll down the page - there's a date only section) – QHarr Dec 10 '20 at 17:59

1 Answers1

1

I could find some java scripts that leads me to the solution

Dim dt As Object
Set dt = .FindElementByCss("input#date")
.ExecuteScript "window.scrollBy(0, 400)"
.ExecuteScript "arguments[0].removeAttribute('readonly')", dt
dt.Clear
dt.SendKeys wsUpload.Range("B5").Value
.SendKeys .Keys.Tab

And another easier solution

.ExecuteScript "document.getElementById('date').value = '" & wsUpload.Range("B5").Value & "'"
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95