Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click image submit button with Codeception

I have a simple question which I'm hoping someone will nail in not time.

I'm just running through some Acceptance tests with Codeception and I'm attempting to click a submit button of type image:

<div id="payment">
    <input name="submit" type="image" value="" alt="Review your order" src="/images/buttons/pay-securely.png">
</div>

Simply using $I->click() results in a failing test:

$I->click('#payment > input[name=submit]');

Any ideas?

like image 840
Phil Avatar asked Oct 20 '25 14:10

Phil


1 Answers

I too have run into trouble with unambiguously specifying what I want to be clicked. Here are two workarounds I have found:

  1. Use a CSS class, or better, an ID, as a selector:

    $I->click(['id'=>'myButtonID']);
    
  2. Use JavaScript / JQuery to trigger the click:

    $I->executeJS("$('input[name=submit]').click();");
    

I prefer the former, because it is easier to do, but I use the latter for cases e.g. where I don't have much control over the code being tested.

like image 183
Scott Weldon Avatar answered Oct 22 '25 19:10

Scott Weldon