在Selenium RC中模拟TAB按键事件 [英] Simulate TAB keypress event in Selenium RC

查看:342
本文介绍了在Selenium RC中模拟TAB按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Java API在Selenium RC中模拟Tab键的按键操作.

I need to simulate a tab keypress in Selenium RC, using the Java API.

我使用以下命令输入了一些文字

I do this after having entered some text using:

selenium.type(input, "mytext");

我尝试了3种替代方法来使标签正常工作:

I've tried 3 alternatives to get the tab working:

selenium.keyPress(input, "\\9");

和:

selenium.focus(input);
selenium.keyPressNative("09");

甚至:

selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2].dispatchEvent(evt);")

我能得到的最好的是在文本后插入一个制表符空间",因此我最终在输入字段中输入了该字符:

The best I can get is a "tab space" to be inserted after my text so I end up with this in the input field:

"mytext    "

我真正想要的是跳到下一个控件.有什么线索吗?谢谢!

What I actually want is to tab to the next control. Any clues? Thanks!

(注意:由于种种原因,我必须使用制表符,而不能使用焦点或选择来选择我想去的元素,所以请不要沿着这条线提出建议!)

(Note: I have to use tab and can not use focus or select to chose the element I want to go to, for various reasons, so no suggestions along these lines please!)

推荐答案

selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB + ""); 

我不使用Java API,但这篇文章谷歌网上论坛表示这是您的解决方案.我无法想象您的问题中的"9"与"09"不同,但是请尝试一下?

I don't use the Java API, but this post from google groups suggests it is your solution. I can't imagine that "9" is different from "09" in your question, but give it a try?

这篇关于在Selenium RC中模拟TAB按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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