[prev in list] [next in list] [prev in thread] [next in thread] 

List:       selenium-devel
Subject:    [Selenium-devel] Keyboard presses
From:       darrell.deboer () gmail ! com (Darrell DeBoer)
Date:       2005-04-15 0:37:18
Message-ID: 2644871205041500472a14e6d7 () mail ! gmail ! com
[Download RAW message or body]

On 4/15/05, Mike Williams <mdub@dogbiscuit.org> wrote:
> On Fri, April 15, 2005 10:24, Patrick Lightbody said:
> 
> > Will we ever be able to simulate keyboard presses (gmail's j/k or Alt-H
> > for Home in JIRA)?
... snip ...

> DOM Level 2 didn't standardise on keypress events.  IE and Mozilla/FireFox
> currently model keypresses differently (though there's a fair overlap).  I
> can't find any way to synthesize a keyboard event; I don't think it can be
> done (though I'm happy to be proven wrong).

In my experience, it's not possible to simply synthesize user-actions
in javascript, and expect the browser to behave as though the user had
performed the action. Eg: IE defines a "click()" method on links, but
this is non-standard and isn't available in FireFox. Instead, it's
necessary to first fire the "click" event, check if the event is
cancelled by javascript, and then emulate the browser response to the
click action. In FireFox, this is something like "window.location.href
= element.href".

This is unfortunate, because a lot of the time we're not really
"driving" the browser, we're actually "emulating" real user actions.
This means that there can be slight differences between a real user
action and the emulated action: one such difference was recently
raised as a bug, where the "target" attribute of a link is ignored in
FireFox.

Emulating a keypress is probably possible, but I've not found a way
for it to be something trivial like
"element.sendEvent(keypressEvent)". The implementation would depend on
the element in question - for a text element we'd have to first send
the various events triggered (keydown, keyup, change, etc) and then
update the text value

I'm sure it's possible to eventually provide a full, rich set of user
actions covering all requirements. I just wanted to point out that
these things aren't quite as easy as I sometimes wish they were. A
good compromise may be to provide a way to send arbitrary keyboard and
mouse event to any element - this should allow testing of javascript
event handlers like "onkeydown" and "onmouseover".
ciao
Daz
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic