1

I am using Robot Framework selenium2library to automate Chromium Embedded application. Requirement is to test whether the window displays a tooltip if Caps Lock key is turned on.

Press Key   #element_id   \\\20             

I am using above code to enable the caps lock key having 20 as ASCII code for Caps Lock key. But the above code is not working. The same syntax works for Enter key(ASCII value 13) and Tab Key(ASCII value 09) as shown below.

Press Key   #element_id   \\\13     
Press Key   #element_id   \\\09     

Can someone please help me to achieve the Caps Lock key press using Robot Framework.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
Chethan Kumar
  • 41
  • 1
  • 8

2 Answers2

2

The short answer is that this isn't supported. Support for non letter keys is limited to those that are specified in the Selenium module. In the Webdriver/Common/Keys.py all the supported keys are found. This is where you find the support for the tab and enter keys. The Caps key is not among them.

When searching the SeleniumHQ issue page for this omission there is one reference: Please add the function of sending "CAPSLOCK" in webdriver. #785. Here the following is stated:

This is out of scope tbh.

Unfortunately not all computers come with a caps lock so closing this as there is a workaround with holding shift

This does not mean it's impossible, but only that this is not supported by Selenium and it's derived SeleniumLibrary. In order to press this key during a test session an OS specific Python module needs to be loaded and it presses this key for you. For windows the Microsoft SendKeys functionality can do this. In this Stack Overflow answer you can find more details on how to use this approach for Windows and Linux.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
1

thanks everyone whoever looked for a solution to the problem.

The found a working solution by using ImageHorizonLibrary available at below

https://github.com/Eficode/robotframework-imagehorizonlibrary https://github.com/Eficode/robotframework-imagehorizonlibrary/blob/master/tests/atest/windows_tests.robot

My working code using above library:

Library           ImageHorizonLibrary

*** Keywords ***  
CheckCapsLockOnNotification  
    Press Key    ${UsernameTextElement}    \\09   #For Tab key  
    Type    Key.CAPSLOCK                          #For CapsLock Key  
    Type    pass                                  #Typing keyboard letters  
    Page Should Contain Element    ${CapsLockOnTooltipElement}  
    Clear Element Text    ${PasswordTextElement}  
    Type    Key.CAPSLOCK
Chethan Kumar
  • 41
  • 1
  • 8
  • Keep in mind that ImageHorizonLibrary uses a desktop level key automation. When running multiple instances of the same browser on the same host, this may cause conflicts. – A. Kootstra Jan 27 '18 at 20:45