keyPress

982 views
Skip to first unread message

David Tran

unread,
Dec 16, 2013, 9:16:38 PM12/16/13
to be...@googlegroups.com
Can someone provide a step and step definition for keyPress method.

I have a search field with no search button and the only way to search is to hit 'enter' key.

Thanks for the help

gokul.sr...@gmail.com

unread,
Dec 18, 2013, 5:45:13 AM12/18/13
to be...@googlegroups.com
Hope the answers section on the below question helps you

http://stackoverflow.com/questions/17333842/can-i-send-raw-keyboard-input-using-mink-and-selenium2?rq=1

Regards,
Gokul
Message has been deleted

Stephen Finney

unread,
Dec 19, 2013, 4:14:55 PM12/19/13
to be...@googlegroups.com
I've had to do this and it's no fun. Here's what I have (note that I'm using Mink with Behat).

Make a step called "I press the enter key" or something similar.

Then, in the context, do this:

1. Find the element that you need using $this->getSession()->getPage()->find("css", <css_selector>);

2. Then, call your web driver's keyPress function, like this: $this->getSession()->getDriver()->keyPress(<element>->getXPath(), 13);

The "13" in the function call is the ASCII code for the "Enter" key. The <element> is the element that you selected in #1.

I hope this helps.

David Tran

unread,
Dec 21, 2013, 12:29:46 AM12/21/13
to be...@googlegroups.com
My solve:

/**
    * @Then /^I hit return$/
    */
    public function iHitReturn()
    {
       $js = 'var e = jQuery.Event("keypress");';
       $js .= 'e.which = 13;';
       $js .= '$("input").trigger(e);';
       $this->getSession()->executeScript($js);
    }

On Monday, December 16, 2013 9:16:38 PM UTC-5, David Tran wrote:
Reply all
Reply to author
Forward
0 new messages