Automate create Statement of Account and print to PDF

Hi there,

I wish to get some help.

I am trying to automate printing to PDF of Statement of Account. I am stuck at the new print dialog window. The Robocode Lab has the last task running, in waiting for the print operation to complete.

The attached is the screen capture and the output rst code.

Thanks,
Yew

Screenshot_2020-09-11_21-52-22|650x500

… code::

*** Settings ***
Documentation   An example robot. Wave Account Access
Library           RPA.Browser
Library           RPA.Excel.Files
Library           RPA.FileSystem
Library           RPA.HTTP
Library           RPA.PDF

… code::

*** Keywords ***
Open The Wave Customer Statement URL
    Open Available Browser   https://my.waveapps.com/login/?next=%2Fb3ec9290-2f2d-4e78-be62-00222ea08c1e%2Fcustomer-statements&service=next

… code::

*** Keywords ***
Log In
    Input Text    username    XXXXXXXXXX
    Input Password    password    XXXXXXXXXX
    Submit Form
    Wait Until Page Contains Element    class:wv-form-field

… code::

*** Keywords ***
Download The Excel file
    #Download from Mobile App TinyWebService
    #Download    http://192.168.1.181:8080//Download/mscustomers.xlsx    overwrite=True

… code::

*** Keywords ***
Fill The Form Using The Data From The Excel File
        Open Workbook    mscustomers.xlsx
        ${customers}=    Read Worksheet As Table    header=True
        Close Workbook
        [Arguments]   ${customer}
        FOR    ${customer}    IN    @{customers}
            Fill And Submit The Form For One Customer    ${customer}
        END

… code::

*** Keywords ***
Open The Excel File
        Open Workbook    mscustomers.xlsx
        ${customer}=    Read Worksheet As Table    header=True
        Close Workbook

… code::

*** Tasks ***
Click on dropdown menu element
    Click Element When Visible     CSS=.wv-select__label

… code::

*** Tasks ***
Select customer from dropdown menu
    #Click Element When Visible    CSS=.wv-select__menu__option
    Input Text    CSS=.wv-input   dbs
    Click Element    CSS=.wv-select__menu__option.is-active

… code::

*** Tasks ***
Click on Create Statement Button
    Click Element    CSS:.wv-button--primary
    #Wait Until Page Contains Element   CSS=.wv-text--strong
    #Capture Page Screenshot

… code::

*** Tasks ***
Click on More Action Button
    Click Element    CSS:.wv-dropdown__toggle

… code::

*** Tasks ***
Select Print from Dropdown Menu
    Click Element    CSS:.wv-dropdown__menu__link.print-link

… code::

*** Tasks ***
Print Menu
    Go To    chrome://print

… code::

*** Tasks ***
Retrieve the AR data for the month and export it as a PDF
    #Open The Wave Customer Statement URL
    #Log In
    Fill The Form Using The Data From The Excel File

Hi @yewengehoe! Welcome to the Forum :wave:

Is your problem that save is not pressed on that print dialog ?

Your task structure seems a bit odd to me. You have multiple tasks for this one thing that you are trying to do ? What is the order of actions you need to execute ?

What is the main task, is it Retrieve the AR data for the month and export it as a PDF ? You could change all other tasks into keywords… and then probably have something like …

Retrieve the AR data for the month and export it as a PDF
    Open The Wave Customer Statement URL
    Log In
    Fill The Form Using The Data From The Excel File
    Handle Printing 

If the problem is about clicking that Save button AND you are working with Windows OS then you can include RPA.Desktop.Windows and grab that save button as savebutton.png and use the following keyword for clicking it…

Mouse Click Image savebutton.png

Hi @mika ! Thank you! :smiley:

I am using Linux OS.

Sorry about the messy task structure, please ignore the last 2 Tasks cells.

I am trying single or a few tasks cell by cell. I have reached the stage to call out the print dialog windows. I am stuck at asking the robot to click on Save button.

After calling out the print window, do I need to tell the robot to focus on it, such as running code:
Go to chrome://print ?

After running this task below, the robot will be waiting for something to complete. When I manually click cancel in the print window, it stop and show some error messages.

code:
*** Tasks ***
Select Print from Dropdown Menu
Click Element CSS:.wv-dropdown__menu__link.print-link

The attached below are screenshot images of my manual operation.

The print dialog window is still a chrome window. The Save to PDF dialog window is Linux OS window.

Thank you again.
:smiley: :smiley:

Hi @mika,

I capture the image where I am stuck.

In the print dialog window, if I click Save and Save or Cancel to complete the process, the task will be completed.

@yewengehoe That print dialog is system dialog you are trying to click and you can’t do that with selenium.

So you can select Print from the dropdown menu, but after that you need to use desktop automation to click Save (that is how I see your problem).

We don’t atm have support for Linux desktop but I have been trying Linux automation to solve your case using image recognition.

If you want to try this “hackish” solution then try my example https://github.com/robocorp/robot-playground/tree/master/desktop

So you need to install that package pyautogui and copy paste desktop.py to your tasks folder, import it as a library like in the example.robot. Then you can try keywords click image and press_key. Grab that save button as an image to click on.

1 Like

Hi @mika,

Should I screenshot the “Save” button as PNG image, as this Save ? If so, where should I save it to in the project/package folder?

About the image recognition and desktop.py code, is there a tutorial to learn more about it? Sorry that I am quite new to Python, Selenium, programming in general.

Thank you for your guidance! :smile:

To begin with you can place that Save button image into your tasks folder so that you can easily try how things work. That click_image takes the image as filepath so that can be placed in more convient place, for example resources after you have verified that this approach works.

Please keep me updated how your task is progressing. I hope that you can manage to complete it :+1:

Some information sites.

Excellent articles and tutorials about RPA

Nice Python tutorial online which is interactive (tip. open wide enough in browser, then you can see editor and shell side-by-side)
https://www.learnpython.org/

General user guide about Robot Framework

Not sure if this helps, but note that when you open the print dialog for PDF output, a PDF is already being generated at this point in time (which is used for the preview).

Maybe it’s even generated before that on another occasion (I don’t know how Wave works and how it’s producing the previews it’s showing in side the web application. If they use pdfjs, it might already be a PDF at that time as well? Maybe something to check).

3 Likes