使用Python的Robot Framework,无需在页面中选择任何按钮或元素即可进行按键 [英] Robot Framework using Python, key press without selecting any button or element in the page

查看:157
本文介绍了使用Python的Robot Framework,无需在页面中选择任何按钮或元素即可进行按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python使用Robot Framework自动化一个应用程序.在某些情况下,加载页面后,我需要按 Enter 而不选择页面的任何按钮或元素.

I am automating one application using Robot Framework using Python. In a certain situation I need to press Enter without selecting any button or element of the page once the page is loaded.

我尝试了以下示例(使用 Press Key ) ,但是它不起作用,因为我不想在页面上按 Enter 之前选择页面的任何特定按钮或元素.

I have tried with the below example (using Press Key), but it didn't work as I don't want to select any specific button or element of the page before press Enter on the page.

示例:

Press Key    text_field     q
Press Key    login_button   \\\13    # ASCII code for the Enter key

IDE不能识别以下关键字,这很可能是由于版本引起的:

The below keyword is not recognized by the IDE, most probably because of version:

Press Key Native

是否有解决此问题的解决方案?

Is there a solution to get rid of this problem?

推荐答案

如果要向页面发送按键事件,但不发送给特定元素,请使用Press Key关键字:

If you want to send a key press event to the page, but not at a specific element - target the <body> element in the page, using the Press Key keyword:

Press Key   xpath=//body        \ue00f    # this is the Page Down key
Press Key   css=body            \ue00e    # and this - Page Up

可以在selenium的源代码

An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.

如果可能,应避免在操作系统中执行击键的IMHO库(例如AutoIt或Java的机器人)-它们使您的自动化脚本依赖于执行计算机(和操作系统),并且仅在本地运行-您无法运行浏览器针对Selenium Hub进行测试(Sauce实验室,Browsertstack等).

IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scripts dependent on the execution machine (and operating system), and local only - you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).

这篇关于使用Python的Robot Framework,无需在页面中选择任何按钮或元素即可进行按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆