1
votes

I'm using robotframework(3.1.2) with seleniumlibrary(3.3.1) to automate zooming a page with Firefox(69.0.1)/geckodriver(0.25.0).

According to this documentation I thought the keyword Press Keys would be useful, but it seems that the firefox instance is not affected.

Am I missing something essential in how to Send Keys to the browser or is this not working by intention?

I've also been playing around with the style-transform solution, but the result wasn't satisfying - as for example the F11 (fullscreen) won't work this way.

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Zoom Automation
    Open Browser    https://www.stackoverflow.com    Firefox
    Maximize Browser Window

    # this should increase the zoom to 120%
    Press Keys   ${None}    CTRL+ADD    CTRL+ADD
    # set firefox to fullscreenmode
    Press Keys   ${None}    F11

    # this code zooms the page, but the result is not the expected one (cropped view)
    # Execute Javascript  document.body.style.MozTransform = 'scale(1.2)'
    # Execute Javascript  document.body.style.MozTransformOrigin = 'top'

According to the accepted answer, I ended up with this code an it works!

import pyautogui

class keyautomation(object):

    ROBOT_LIBRARY_VERSION = 1.0

    def __init__(self):
        pass

    def press_ctrl_add(self):
        pyautogui.keyDown('ctrl')
        pyautogui.keyDown('add')
        pyautogui.keyUp('ctrl')
        pyautogui.keyUp('add')
*** Settings ***
Library    SeleniumLibrary
Library    keyautomation

*** Test Cases ***
Zoom Automation
    Open Browser    https://www.stackoverflow.com    Firefox
    Maximize Browser Window
    Press Ctrl Add
    Press Ctrl Add
1

1 Answers

1
votes

You can use pyautogui library in robot framework. This will help to perform mouse and keyboard actions.

Ex for pressing F11:

Keydown f11

Keyup f11

https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-typewrite-function