New Selenese Command – sendKeys

I have just added a new command sendKeys to Selenium IDE. I believe that this is the way forward and it should fix the problem you have been facing with the typeKeys command (issue 3861). Here is the important section from the reference.

Command: sendKeys | locator | text

*Experimental* Simulates keys pressed as though you typed the value key-by-key on the specified element.

This simulates a real user typing every character in the specified string; it is also bound by the limitations of a real user, like not being able to type into a invisible or read only elements. This is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.

Unlike the simple type command, which forces the specified value into the page directly, this command will not replace the existing content. If you want to replace the existing contents, you need to use the simple type command to set the value of the field to empty string to clear the field and then theĀ sendKeys command to send the keystrokes for what you want to type.

I have currently marked the sendKeys command as experimental. I think that the sendKeys command will change a bit to allow you to specify the pressing of control keys like shift and control. I want to get some feedback from you before I finalise it.

Migrations plans

I am planning to update my Selenium Expert plugin soon and give it the ability to convertĀ  all typeKeys commands to sendKeys commands. This should make the migration of existing scripts to the commands a one click thing.

Another solution would be to simply change the existing typeKeys command instead of introducing the sendKeys command. Since, the two implementations are similar but not the same, some existing tests would break. Introducing a new command would allow you to experiment with it and provide us with your feedback. Tell us what you think about the sendKeys command. Tell us if you want to have two commands or if you want to have just typeKeys with the new Selenium 2 implementation.

This entry was posted in Selenium IDE and tagged , , , , , , , , . Bookmark the permalink.

17 Responses to New Selenese Command – sendKeys

  1. Pingback: Selenium IDE v1.9.0 Released and Includes Firefox 14 Support | Really Simple Thoughts of a Perpetual Learner

  2. Tapio says:

    Any idea when selenium standalone server will support the new command?

  3. mamta says:

    Hi Samit,

    Neither sendKeys nor typeKeys is working on selenium ide 2.1.0.

    Anyupdates as in when these will be fixed?

    click
    id=addRequest

    typeKeys
    id=autoCompleteInput
    davi

    • Samit Badle says:

      Hi Mamta,

      I guess you have already tested the new Selenium IDE version where typeKeys is fixed. However, I am not aware of any issues with sendKeys. Can you raise an issue for it if is not fixed yet?

      Cheers,
      Samit

  4. Adriana says:

    Hello,

    I just installed IDE 2.3.0 on Firefox 17 and it seems that now, using record, it automatically takes sendKeys, instead of type. Any idea why this is replaced and how can it take again type, as it did on IDE 1?

    Thanks,
    Adriana

    • Samit Badle says:

      Hi Adriana,

      It has been reverted. And will be available in the new release. Hopefully in a day or two.

      Cheers,
      Samit

  5. Bonnie says:

    Hi,

    I’ve had a problem with selenium ide that seem to be to do with the sendKeys command, which is now being recorded instead of the type command in a lot of cases (am I able to change this?). I typed into a field and clicked away before replacing this text with something else. When I played this back, the second input was added to the first input rather than replacing it. This is also causing a problem in the quick search box of the site, which has the text “search” autopopulated. If I try to perform a search with sendKeys instead of type, my search term has the word “search” bolted onto the front of it. It is not possible to do this manually – as soon as you select the quick search box the text disappears.

    Many thanks,

    Bonnie

    • Samit Badle says:

      Hi Bonnie,

      It has been reverted. And will be available in the new release. Hopefully in a day or two.

      Cheers,
      Samit

  6. Fred says:

    How do I send non-printing characters, such as “down arrow” in Selenium IDE (not Java, etc.) using sendKeys? I can’t find any discussion of this on the web.

    I want the equivalent sendKeys command to the below (down arrow):

    keyPress
    (locator)
    40

    I could’ve sworn I already asked this, but my question seems to have disappeared.

      • Fred says:

        Yes, that works, though the way modifier keys are handled is a bit different than my existing scripts that use keydown/keypress/keyup. With those commands you can effectively depress a modifier key, then send as many other keypresses are you want before releasing the modifier (with a separate command).

        Under this approach it appears I must add the modifier stuff to each sendKeys() that I want to emit when that modifier is down.

        • Samit Badle says:

          Hi Fred,

          Yes indeed you need to add the modifier stuff each time. Webdriver automatically releases all the pressed modifier keys. Since it is part of the webdriver spec, there is not much I can do.

          If it eases your pain a bit, maybe you can construct the keystrokes using a stored variable and send it all in one sendKeys command?

          Cheers,
          Samit

      • Fred says:

        Actually, I have a more important request. Can you please move doSendKeys() from selenium-api-override.js under the ide to selenium-api.js (under javascript/selenium-core/scripts)? My goal is to switch existing Selenium RC (v1.0) scripts over from using keyPress() to sendKeys(), but obviously if it only works in Selenium IDE and not when running Selenium HTML scripts, I can’t make the change. I don’t think there’s any reason my request would be difficult as the command isn’t defined in selenium-api.js so there’s no backcompat issue.

        • Samit Badle says:

          Hi Fred,

          Selenium Core (the file selenium-api.js) and Selenium RC are now legacy, hence only bugfixes are expected and no new features. This was the reason I decided to implement it as Selenium IDE only command.

          You can always patch your version of Selenium RC and add the function there. You should plan on moving away from Selenium RC, if you use webdriver backed selenium, you can directly use sendkey on the driver instance. Alternatively, you can continue to use Selenium IDE, which is getting scheduler based test execution soon.

          Cheers,
          Samit

  7. uvu says:

    `sendKeys` doesn’t work in Selenium webdriver (PHPUnit).

    I am testing ACE Editor that it was in my project. I typed in the `sendKeys` command in SeleniumIDE that is fine but when I tested webdriver (PHPUnit) it doesn’t work. Has another command like `sendKeys` ? If you have another command like `sendKeys` if so please give me reply. Note `typeKeys` also doesn’t work for ACE Editor

Comments are closed.