<form action="/myform5"> <div><span> <button id="submit5">Click</button> <input type="image" src="myimage.png" alt="image submit" name="submit_image" value="image" /> </span></div> </form> <a href="/myotherlink">test link</a> </body> </html> EOF; $b = new myClickBrowser(); $b->setHtml($html); try { $b->click('nonexistantname'); $t->fail('->click() throws an error if the name does not exist'); } catch (Exception $e) { $t->pass('->click() throws an error if the name does not exist'); } try { list($method, $uri, $parameters) = $b->click('submit5'); $t->pass('->click() clicks on button links'); } catch (Exception $e) { $t->fail('->click() clicks on button links'); } list($method, $uri, $parameters) = $b->click('test link'); $t->is($uri, '/mylink', '->click() clicks on links'); list($method, $uri, $parameters) = $b->click('test link', array(), array('position' => 2)); $t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); list($method, $uri, $parameters) = $b->click('image link');
<a href="/submitimagelink"><img src="myimage.gif" alt="submit" /></a> <input type="submit" id="orphaned-input-submit" /> <ul class="css-selector-test"> <li>my first <a href="myfirstlink">paragraph</a></li> <li>my second <a href="mysecondlink">paragraph</a></li> </ul> </body> </html> EOF; $b = new myClickBrowser(); $b->setHtml($html); try { $b->click('nonexistantname'); $t->fail('->click() throws an error if the name does not exist'); } catch (Exception $e) { $t->pass('->click() throws an error if the name does not exist'); } try { list($method, $uri, $parameters) = $b->click('submit5'); $t->pass('->click() clicks on button links'); } catch (Exception $e) { $t->fail('->click() clicks on button links'); } list($method, $uri, $parameters) = $b->click('test link'); $t->is($uri, '/mylink', '->click() clicks on links'); list($method, $uri, $parameters) = $b->click('test link', array(), array('position' => 2)); $t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); list($method, $uri, $parameters) = $b->click('image link');