Take Screenshot of a Website

This process takes a screenshot of Yahoo’s home page and saves it on the desktop with the date and time appended to the file’s name.

Folder.GetSpecialFolder SpecialFolder:Folder.SpecialFolder.DesktopDirectory \
                        SpecialFolderPath=> DesktopDirectoryPath

WebAutomation.LaunchChrome Url:'http://yahoo.com' \ 
                                    WindowState:WebAutomation.BrowserWindowState.Maximized \
                                    ClearCache:False \
                                    ClearCookies:False \
                                    CustomUserAgentString:'' \ 
                                    BrowserInstance=> Chrome

WebAutomation.DataExtraction.TakeScreenshotSaveToFile BrowserInstance:Chrome \
                                    File:DesktopDirectoryPath+'\ScreenShot.png' \
                                    FileFormat:WebAutomation.FileFormat.Png

WebAutomation.CloseWebBrowser BrowserInstance: Chrome

File.RenameAddDateOrTime Files:DesktopDirectoryPath+'\ScreenShot.png'  \
                        DateTimeToAdd:File.DateTimeToAdd.Current \
                        DateTimePosition:File.AddTextPosition.AfterName \
                        DateTimeSeparator:File.Separator.Space \
                        DateTimeFormat:'yyyy-MM-dd@hh-mm' \
                        IfFileExists:File.IfExists.DoNothing \
                        RenamedFiles=> RenamedFiles

Display.ShowMessage Title:'Screenshot taken' \
                    Message:'The screenshot is stored in the file'+RenamedFiles[0] \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed2

In more detail:


The process retrieves the desktop path, launches Chrome and navigates to Yahoo’s home page. It then takes a screenshot, saves the file on the desktop and closes the browser. Finally, it appends the date and time to the file’s name.

Step 1: Retrieve the Desktop Path and Navigate to Yahoo’s home page

Retrieve the path to the “Desktop” folder.

Folder.GetSpecialFolder SpecialFolder:Folder.SpecialFolder.DesktopDirectory \
                        SpecialFolderPath=> DesktopDirectoryPath

WebAutomation.LaunchChrome Url:'http://yahoo.com' \ 
                                    WindowState:WebAutomation.BrowserWindowState.Maximized \
                                    ClearCache:False \
                                    ClearCookies:False \
                                    CustomUserAgentString:'' \ 
                                    BrowserInstance=> Chrome

  1. Use the “Folder.GetSpecialFolder” action and save the path to the “DesktopDirectoryPath” output variable.
  2. Use the “WebAutomation.LaunchChrome” action:
    1. Set the “Url” argument to “http://yahoo.com”.
    2. Set the “WindowState” argument to “WebAutomation.BrowserWindowState.Maximized”.
    3. Store the web browser instance in the “Chrome” output variable.

Step 2: Take a Screenshot

Take a screenshot of the web page and close the Chrome.

WebAutomation.DataExtraction.TakeScreenshotSaveToFile BrowserInstance:Chrome \
                                    File:DesktopDirectoryPath+'\ScreenShot.png' \
                                    FileFormat:WebAutomation.FileFormat.Png

WebAutomation.CloseWebBrowser BrowserInstance: Chrome
  1. Use the “WebAutomation.DataExtraction.TakeScreenshotSaveToFile” action:
    1. Set the “BrowserInstance” argument to “Chrome”, which is the output variable of the “WebAutomation.LaunchChrome” action.
    2. Set the “File” argument to “DesktopDirectoryPath+‘\ScreenShot.png’”, where “DesktopDirectoryPath” is the output variable of the “Folder.GetSpecialFolder” action, used in the first step, and “ScreenShot” will be the file’s name.
    3. Set the “FileFormat” argument to the desired format, such as “png” or “jpg”.

  2. Use the “WebAutomation.CloseWebBrowser” action, by setting the “BrowserInstance” argument to “Chrome”.

Step 3: Append the Current Date and Time to the File’s Name

Rename the file by adding the date and time, and inform the user about the new name.

File.RenameAddDateOrTime Files:DesktopDirectoryPath+'\ScreenShot.png'  \
                        DateTimeToAdd:File.DateTimeToAdd.Current \
                        DateTimePosition:File.AddTextPosition.AfterName \
                        DateTimeSeparator:File.Separator.Space \
                        DateTimeFormat:'yyyy-MM-dd@hh-mm' \
                        IfFileExists:File.IfExists.DoNothing \
                        RenamedFiles=> RenamedFiles

Display.ShowMessage Title:'Screenshot taken' \
                    Message:'The screenshot is stored in the file'+RenamedFiles[0] \
                    Icon:Display.Icon.None \
                    Buttons:Display.Buttons.OK \
                    DefaultButton:Display.DefaultButton.Button1 \
                    IsTopMost:False \
                    ButtonPressed=> ButtonPressed2

  1. Use the “File.RenameAddDateOrTime” action. This action changes the name of one or more files by adding the date and time in the desired format:
    1. Set the “Files” argument to “DesktopDirectoryPath+'\ScreenShot.png”, which is the screenshot saved on the desktop.
    2. Set the “DateTimeFormat” to the desired format, such as “yyyy-MM-dd@hh-mm”.

  2. Inform the user of the new file name, using the “Display.ShowMessage” action. As the “RenamedFiles” list contains only one file, this is in the “RenamedFiles[0]” position. Note that list indexes start with 0.