3

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?

Phil
  • 76
  • 1
  • 6

2 Answers2

4

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.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
  • 2
    Nice! Took me a while but finally saw your answer and appropriately accepted. Shame we have to resort to such workarounds. – Phil Jul 20 '15 at 13:03
0

I've been in touch with Codeception directly with no reply on the matter. With no way of testing this (and the obvious design flaw in using an image submit button - I mean, are we in the 90s or what?!) I've now changed the input to a proper submit button and CSS that bad boy!

Thought I'd answer my own question and leave it here in the (hopefully unlikely) event that another poor soul has inherited shoddy work.

Phil
  • 76
  • 1
  • 6
  • To be honest, I didn't have the exact problem, but I did have the problem of "several buttons with the same text", and Google found me this question... – Mark Harrison Dec 17 '19 at 12:17