• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!