views:

219

answers:

2

My form has an ajax handler provided by jquery.forms.js.

form.ajaxForm({
  dataType: 'json',
  clearForm: true,
  success: function (data)
  {
     form.replaceWith(data);
  }
});

I'm testing this using selenium (the python RC interface), and it works when I click() the button, but not when I submit the form:

    locbase = "dom=document.forms[0]"
    SEL.type(locbase + ".elements[0]", text)
    SEL.select(locbase+".elements[2]", "label=%s" % username)
    SEL.submit(locbase) # DOESNT WORK
    SEL.click(locbase+".elements[3]") # WORK!

By "doesn't work", I mean that the form submits, but not via AJAX.

I guess this is a problem with the form. How can I tell (manually) that both my ajax is bound for both submitting the form and clicking on the button, and what do I have to do to make it work?

+2  A: 

I use FireQuery plugin for firefox to see what jQuery is bound to an element. I tend to use click() when there is a button on the page for form submits. Its very rare that you will see a form that doesnt have a button and if it doesnt you can always do typeKeys() call.

Edit from Comment:

Other than clicking or keyPress I don't think there is a situation where they would submit because normally the submit is bound to a button e.g or jQuery bindings to a button or there is a listener for keyboard interaction. A user can't submit() something without there being a bound point on the page

AutomatedTester
So does this mean its not a problem that submit() doesn't work? What about pressing Enter or something?
Paul Biggar
If the Submit button is bound to your jQuery Form then clicking it will be fine, or you can do a keyPress("\13"). I don't know if submit doesn't work but in the 2+ years of using Selenium I have never needed to use submit() on a form
AutomatedTester
I mean, is it possible that the user might "submit" the form instead of "click"ing it?
Paul Biggar
Other than clicking or keyPress I don't think there is a situation where they would submit because normally the submit is bound to a button e.g `<input type=submit value=submit />` or jQuery bindings to a button or there is a listener for keyboard interaction. A user can't submit() something without there being a bound point on the page.
AutomatedTester
Great, thanks. If you could amend your answer to say that you can't have a submit() without a click() without doing something special, I'll mark it as correct.
Paul Biggar
I have upated my answer
AutomatedTester
A: 

When you say "it doesn't work" do you mean the form does not submit or it submits but not via ajax?

What about a simple test

form=ajaxForm{(
 //options
});

form.submit();//does this work?
czarchaic
I mean that it submits, but not via ajax.
Paul Biggar