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...?

4
  • getdatepicker.com/4 , stackoverflow.com/a/40367539, stackoverflow.com/a/59761118 Commented Dec 10, 2020 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. Commented Dec 10, 2020 at 17:54
  • I have no great idea about bootstrap. How can I get the link to the datepicker? Commented Dec 10, 2020 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) Commented Dec 10, 2020 at 17:59

1 Answer 1

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 & "'"
Sign up to request clarification or add additional context in comments.

2 Comments

^^ or that :-) works. I am always suspicious of Excel when it comes to reading in dates from cells however.
Thanks a lot, my tutor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.