Press key - Simulate ESC on the keyboard

Good afternoon, I am trying to use the keyword Press Keys to simulate the ESC on the keyboard but I am not having success. I am not finding the correct format or document for which the keyword works or if in my case this would be the best use.
My case: In my automation, at the end of my test case the google chrome automatic printing screen is displayed, automatic printing of an invoice. However, I am unable to interact with this screen by clicking on cancel (since it is from the browser) and I cannot simply simulate the ESC for its closing. Could you help me with the best way for this issue?

The Press Keys has it’s limitations and sometimes browser or the application doesn’t work in the desired way. The underlying Selenium sends emulated events and therefore it doesn’t trigger the action users want.

If really want to test this functionality from the browser, you need operating system specific library to do the integration. But generally I would advise against testing this type of functionality, unless it’s brings real business value.

What is the code you have so far? You say that Press Keys isn’t working for you but is an error being thrown/reported? Press Keys None ESC ? Or ?

Hi Rafael,

I have noticed from using other chromium based browsers that the print dialogue opens in a new window, where as on chrome it is appearing as a modal dialogue on the tab being printed.

Based on that observation only, perhaps chrome is also creating a new window for the print dialogue and is simply displaying the window attached to the source window/tab.

I would try adding Get Window Names in two places, 1. just before the press keys line, and 2. just before the step that launches the print dialogue. doing this will tell you if a new window is being created or not, if so it may be as simple as Close Window

Good luck, and I hope this helps,

Dave.

1 Like

Hello aaltat, thank you very much for your help. Could you tell me which library for the operating system you are referring to?
Actually I don’t need to test this screen, I just need to close it so that my scenario is done, my specific scenario is a restaurant management system, to finish the table I need to pay it and this invoice screen is automatically displayed every time I finish the table. I don’t need to test it, I just need to close it, but I can’t do it with robot and selenium. Did you understand my scenario?
Then I know that pressing ESC on the keyboard the screen disappears, so I thought about this format, and I can’t imagine another way to make and close this screen, I tried a Go To directly to the main screen and it works, but I found it a bit hardcore to do that Hahahaha’

Hello hobet, it just doesn’t work, it doesn’t give any error, but the command is not executed, I tried:
Press Keys None ESC
Press Keys None ESCAPE
and several others exchanging esc / escape for the key’s ASCII code, I tried using the body instead of none, tried many variations and was unsuccessful.

Hello damies13, I understood what you said and I am analyzing the use of Get Window Names, but I confess that I never used this keyword and in practice I did not understand how to apply it. But I will take a look and try this suggested way.

I am inserting this image that is better, in the exact way that the screen is displayed, it is a modal that overlaps the system screen.

Since that preview window does look to overlap with the actual browser window beneath (it goes over your toolbar below the url) - that window is beyond anything that Selenium can interact with. As @aaltat suggested, you need to have some operating system specific way to interact with the keyword to send the esc key press. Maybe robotframework-autoit or hooking up some pyautogui python code to cancel that for you …

Hi @ r.bcoutinho
This is my solution
Switch Window NEW
Press Keys None TAB+SPACE
Switch Window MAIN
Hope to help you