I'm attempting to test a node's form that has multiple fields that allow arbitrary numbers of entries. As such, there are several "Add Another Item" entries. In the SimpleTest docs (I think, I may have found it somewhere else ... code samples or something) it has examples for how to trigger the click of the Add Another Item button. Something like this:

$this->drupalPost(null, array(), t('Add another item'));

The trouble with this is that is targets the value of the field and the value is not unique across the page. In the docs it also suggests that you can pass in an array as the third parameter to drupalPost:

$this->drupalPost(null, array(), array('path' => '', 'triggering_element' => 'something_add_more');

Unfortunately I don't know what to set the path to. The default doesn't work (/system/ajax I believe) and I don't know what path drupal is using to trigger the ajax request to begin with when you manually click the button (if it's ajax at all).

I have also tried just passing the id or name of the button as the third parameters with no luck.

So here's my question: How can I uniquely select any one of the "Add Another Item" buttons found on the page from within the SimpleTest environment?


I think FileWidgetTestCase::testMultiValueWidget() should be useful as an example.

As you can see there, only drupalPostAJAX() supports to target the actual button based on the name, for drupalPost(), they actually mess with the HTML source ($buttons is a xpath result that can be altered).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.