• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JWebUnit: How do I simulate clicking enter in a text field?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm using the latest version of JWebUnit-HtmlUnit plugin (2.2) along with Maven 2.2 to run some test cases. My question is, how do I simulate a user clicking the "Enter" key when inside a text field? I'm trying to write a test case for clicking enter to see if it acts like clicking the Submit button on my page.

Thanks, - Dave
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't think JWebUnit can do that; it'd be browser-specific anyway.

Hitting enter in a text field causes a form submit - not a click on the submit button. So the only difference would be if the click on the submit button does something beside simply submitting the form.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my web page, I have tied an "onkeypress" event handler to the text field, and if I detect an enter key, I call a Javascript function that simulates clicking the submit button. So any way JWebUnit can invoke that event handler?

Thanks, - Dave
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why the JavaScript? Unless you do something special to prevent it, most forms submit automatically if you hit the enter key in a text field.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need the JS because there are two type=submit buttons on the page, and the first one is a "Cancel" button, so clicking "Enter" executes the Cancel action, which I do not want.

Getting back to the original question, do you know how I can get JWebUnit to execute Javascript, or at least, the event handlers associated with buttons?

Thanks, - Dave
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic