FireEvent command in Selenium - how can arguments be passed?

3,084 views
Skip to first unread message

Treighton

unread,
May 23, 2011, 10:45:33 PM5/23/11
to Selenium Users
Hi - new user of Selenium here. How do I use Seleium to fire an event
on a control on a page and also pass arguments to the event? I know of
a way to do this in WatiN and I'm trying to reproduce it in Selenium.

I'm attempting to fire the onkeydown event of a Select element. It
should trigger a JavaScript function I've added on the page which will
select options in the list depending on a sequence of keys pressed.
So, for example, I'm trying to simulate the keydown event with the '1'
key on the keyboard being pressed, then the '9' key.

I've looked at FireEvent, but it's parameters only allow the element
the event if fired on and the name of the event to be defined; that is
selenium.fireEvent("mySelect", "onkeydown)

I looked at the keypress command, but it hasn't reproduced the user
behaviour that my test is trying to simulate. In my page, if the user
hits "1", "9", "6", "6", the option "1966" should be selected. I've
tried
keypress("mySelect", "1")
keypress("mySelect", "9")
keypress("mySelect", "6")
keypress("mySelect", "6")
but this is not selecting the required item. I suspect that the
JavaScript function is not actually being triggered by the keyPress
function.

Lutfi Dughman

unread,
May 24, 2011, 12:26:28 PM5/24/11
to seleniu...@googlegroups.com
the 'on' part sholdnt be included 



the command should be 


selenium.fireEvent("mySelect", "keydown").


not sure about the keypress though, maybe you could try the type command


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Treighton

unread,
May 24, 2011, 8:48:23 PM5/24/11
to Selenium Users
Confirmed that keypress does not trigger the keydown event handling
JavaScript code.

Thanks for the comment, Lutfi, but it doesn't address the question.
How can arguments be passed to the event on the FireEvent method?

Treighton

unread,
May 24, 2011, 9:11:05 PM5/24/11
to Selenium Users
I've also experimented with type("mySelect","1966"). This does select
the "1966" option, but it is because this is native browser behaviour
in Firefox 4. I've used Firebug and when the type and keypress
commands are executed by Selenium, this doesn't seem to also trigger
the JavaScript functions that are attached to the Select control. I
still think what's required is to explicitly call the fireEvent method
in Selenium, but when my JavaScript function depends on having
arguments passed to the handler, this doesn't work.

Seems like a missing feature in Selenium to me.

Mark Collin

unread,
May 25, 2011, 3:43:57 AM5/25/11
to seleniu...@googlegroups.com
Is this what you are looking for?

JavascriptLibrary _js = new JavascriptLibrary();
WebElement elementToClick = driver.findElement(By.xpath("//foo"));
_js.callEmbeddedSelenium(driver, "doFireEvent", elementToClick,
"mousedown");

--


You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Treighton

unread,
May 26, 2011, 5:05:59 AM5/26/11
to Selenium Users
Doesn't look like it, unfortunately. As an example, I'm after being
able to raise the keydown event, such that the Javascript function
that handles it can look at the argument passed to the event and get
the key that was pressed. In _js.callEmbeddedSelenium(driver,
"doFireEvent", elementToClick,
> "mousedown"); I still don't see any arguments passed to the event.


On May 25, 5:43 pm, "Mark Collin" <m...@ardescosolutions.com> wrote:
> Is this what you are looking for?
>
> JavascriptLibrary _js = new JavascriptLibrary();
> WebElement elementToClick = driver.findElement(By.xpath("//foo"));
> _js.callEmbeddedSelenium(driver, "doFireEvent", elementToClick,
> "mousedown");
>
>
>
>
>
>
>
> -----Original Message-----
> From: seleniu...@googlegroups.com
>
> [mailto:seleniu...@googlegroups.com] On Behalf Of Treighton
> Sent: 25 May 2011 02:11
> To: Selenium Users
> Subject: [selenium-users] Re: FireEvent command in Selenium - how canargumentsbe passed?
>
> I've also experimented with type("mySelect","1966"). This does select the
> "1966" option, but it is because this is native browser behaviour in Firefox
> 4. I've used Firebug and when the type and keypress commands are executed by
> Selenium, this doesn't seem to also trigger the JavaScript functions that
> are attached to the Select control. I still think what's required is to
> explicitly call the fireEvent method in Selenium, but when my JavaScript
> function depends on havingargumentspassed to the handler, this doesn't
> work.
>
> Seems like a missing feature in Selenium to me.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

Arian

unread,
Jan 29, 2013, 12:48:35 AM1/29/13
to seleniu...@googlegroups.com
Hi Treighton,

Were you able to solve this issue? I too am facing the exact same problem.

Regards,
Rohan
Reply all
Reply to author
Forward
0 new messages