VBA Selenium Date Input

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
I have issues to sendkeys into date input control using following code. The existing date input content cannot be cleared

VBA Code:
[/
    auto.FindElementById("startDate").Click
    auto.FindElementByXPath("//*[@id='calendar']/tbody/tr[1]/td[7]").Click
]


However, it is workable with this code but I would like to automate this step so that I don't have to manually change date position in calendar every time I run the code.

VBA Code:
[/
auto.FindElementById("startDate").Clear
auto.FindElementById("startDate").Sendkeys("2021-09-04")
]
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Do you mean you want the current date?
VBA Code:
auto.FindElementById("startDate").Sendkeys(Format(Date, "YYYY-MM-DD"))
 
Upvote 0
Do you mean you want the current date?
VBA Code:
auto.FindElementById("startDate").Sendkeys(Format(Date, "YYYY-MM-DD"))
Hi John not current date, I have the date format in 2021-09-04-12:00 AM. When I send keys , it has been truncated to 2021-09-04-12:0 causing no correct date is selected. Any advise on this scenario ?
 
Upvote 0
I have the date format in 2021-09-04-12:00 AM
Assuming this is a string variable named theDate, try:
VBA Code:
auto.FindElementById("startDate").Sendkeys(Left(theDate, 10))
I can't really help you further without seeing the web page.
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top