如何使用 robotframework/seleniumlibrary 自动化 Firefox 缩放功能 [ctrl]+[+]?

How to automate Firefox zoom functionality [ctrl]+[+] with robotframework/seleniumlibrary?

我将 robotframework(3.1.2) 与 seleniumlibrary(3.3.1) 结合使用,以使用 Firefox(69.0.1)/geckodriver(0.25.0) 自动缩放页面。

据此documentation我认为关键字Press Keys会有用,但似乎firefox实例不受影响。

我是否遗漏了一些关于如何将密钥发送到浏览器的基本内容,或者这不是故意的?

我也一直在尝试样式转换解决方案,但结果并不令人满意 - 例如 F11(全屏)不会以这种方式工作。

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Zoom Automation
    Open Browser    https://www.whosebug.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'

根据接受的答案,我最终得到了这段代码,它可以工作!

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.whosebug.com    Firefox
    Maximize Browser Window
    Press Ctrl Add
    Press Ctrl Add

您可以在机器人框架中使用pyautogui 库。这将有助于执行鼠标和键盘操作。

例如按 F11:

按键 f11

键盘输入 f11

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