Simulate TAB keypress event in Selenium RC

前端 未结 5 1109
滥情空心
滥情空心 2021-02-07 08:10

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\");
<         


        
相关标签:
5条回答
  • 2021-02-07 08:47
    selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB + ""); 
    

    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?

    0 讨论(0)
  • 2021-02-07 09:03

    Some functions may used Onblur. It will trigger the function when the field lose the key focus. here we can use fireEvent with "blur" or "focus" command as follows: command: fireEvent target: id=your_field_identification value: blur

    Reference: http://qaselenium.blogspot.com/2011/01/how-to-triger-tab-key-in-selenium.html

    0 讨论(0)
  • 2021-02-07 09:11

    Try the official TAB char: \t or \u0009

    0 讨论(0)
  • 2021-02-07 09:11

    Improvising Ryley's answer, we can use

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

    I tried this method for VK_CONTROL in IE and it worked good.

    0 讨论(0)
  • 2021-02-07 09:14

    Use typeKeys():

    Quoting the above link:

    Unlike the simple "type" command, which forces the specified value into the page directly, this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect. For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in the field.

    In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed.

    0 讨论(0)
提交回复
热议问题