我正在使用robotframework(3.1.2(和seleniumlibrary(3.3.1(来自动缩放Firefox(69.0.1(/geckodriver(0.25.0(的页面。
根据此文档,我认为关键字Press Keys
会很有用,但似乎Firefox实例不受影响。
我是否错过了如何将密钥发送到浏览器的基本内容,或者这不是故意工作的?
我也一直在尝试样式转换解决方案,但结果并不令人满意 - 例如 F11(全屏(不会以这种方式工作。
*** 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'
根据接受的答案,我最终得到了这段代码,它有效!
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
您可以在机器人框架中使用pyautogui库。这将有助于执行鼠标和键盘操作。
例如,按 F11:
按键 f11
键控 f11
https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-typewrite-function