我正在尝试在 Robot Framework 中使用 F12
发送,可能是通过使用 Selenium 库的 send special key
。
我发现此页面列出了常见不常见键的键码 https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.keys.html其中 F12
被列为\ue03c。
我已经尝试了所有我能想到的反斜杠和引号的组合,但都没有用。如何在 Robot Framework 中发送 F12?
此外,在下一步中我需要发送 F16 但它未在链接页面中列出 - 我该如何发送它?
编辑:我不需要将键发送到特定元素,我只想使用其键盘快捷键触发菜单选项。
编辑 2:我仅限于 Selenium Library 3.1。
最佳答案
来自 SeleniumLibrary 3.3 Press Keys
引入了以下功能:
Simulates user pressing key(s) to an element or on the active browser.
这允许用户向浏览器本身发送特殊的键或组合键,除了网络元素。
Sleep 5s
Press Keys //*[contains(@id,'textfield')] AAAAA # enter text "AAAAA" to a textfield
Sleep 5s
Press Keys None F3 # F3 into browser
Sleep 5s
Press Keys None CTRL+Z # Send CTRL+Z to browser to Undo "AAAAA" in the textfield
Sleep 5s
这是三个 Press Keys
调用的输出日志:
第一个只需在文本字段中输入:
KEYWORD SeleniumLibrary.Press Keys //*[contains(@id,'textfield')], AAAAA Documentation: Simulates user pressing key(s) to an element or on the active browser. INFO Sending key(s) ('AAAAA',) to //*[contains(@id,'textfield')] element. INFO Sending keys AAAAA
第二个向浏览器发送特殊 key :
KEYWORD SeleniumLibrary.Press Keys None, F12 Documentation: Simulates user pressing key(s) to an element or on the active browser. INFO Sending key(s) ('F12',) to page. INFO Pressing special key F12 to browser.
第三个,按住
CONTROL
,发送一个Z
,然后松开CONTROL
。总而言之,执行Undo
操作。全部发送到页面。KEYWORD SeleniumLibrary.Press Keys None, CTRL+Z Documentation: Simulates user pressing key(s) to an element or on the active browser. INFO Sending key(s) ('CTRL+Z',) to page. INFO Pressing special key CONTROL down. INFO Sending key Z INFO Releasing special key CONTROL.
至于F16,据此page , SHIFT+F4=F16,或者至少在 Windows 上。
关于selenium - 您如何在 Selenium 库/机器人框架中发送特殊 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54076764/