Search code examples
javaselenium-chromedriverautoit

How to pass date in file name to get saved in required directory using autoIt selenium java?


I am using autoIt to handle the saveAs dialog box in selenium java. Here, I should save the pdf file in required directory

ControlFocus("Save As","","Edit1")
ControlSend("Save As","","Edit1","-----My file path\file_name.pdf")
ControlClick("Save As","","Button2")

Is it possible to add today's date or last weekend date(Saturday) in my file name and send in the file path to get saved?


Solution

  • Does this help you out?

    #include<date.au3>
    Dim $Y, $M, $D
    $today = _DateTimeFormat(_NowCalc(), 2)
    ConsoleWrite($today & @CRLF ) ; Regional settings today
    $today_format = @YEAR &'-' & @MON & '-' & @MDAY
    ConsoleWrite($today_format & @CRLF ) ; fixed format today
    $lastSaturday = _DayValueToDate(_DateToDayValue(@YEAR, @MON, @MDAY) - _DateToDayOfWeek(@YEAR, @MON, @MDAY), $Y, $M, $D)
    ConsoleWrite($lastSaturday & @CRLF) ; last SATURDAY
    
    $yourPathWithDate = "My file path\" & $today_format & "_file_name.pdf"
    ConsoleWrite($yourPathWithDate & @CRLF)
    
    ControlFocus("Save As","","Edit1")
    ControlSend("Save As","","Edit1","My file path\file_name.pdf")
    ControlClick("Save As","","Button2")