2
votes

Codeception does not appear to be submitting a form:

<form action="https://test.sagepay.com/gateway/service/vspform-register.vsp" method="POST" id="SagePayForm" name="SagePayForm">
  <button id="sagepay_submit" class="button_submit">Pay Now</button>
  <input type="hidden" name="navigate" value="" />
  <input type="hidden" name="VPSProtocol" value="2.23">
  <input type="hidden" name="TxType" value="PAYMENT">
  <input type="hidden" name="Vendor" value="vendorname">
  <input type="hidden" name="Crypt" value="@361cac3da8d933c239b5850de6c8eec4ec50e582025083c15f39c5cb0254e5b63bb0823eddd6d17eb4d53184cb25ac2b5f11f3e3aa975e83141f837193cc74313e26b69e1babe5e7c6a7dd272d555fc5f7d851be97848fe817e8925668315a5d9fdc7acffaab3af03d3d8f4cdc185c400d8825ff961bde8935fabdb57e4ea18320f0fd2bb9770d9b24f61c737ba493c6b3ebf9eff3e897756cd92df8963418946e59babec72813b872b6ff4ff806441ff473c634e08858e6218f6d6115c5443499f12081de168b7b0c089c21f6282bb528459c3a2449fee187294a222e2029117e891e3f13d8aebb434b42b817192541b8382dbc9dac57bf64384e98da086c13368cc31fd71e3c2a37a5e8ab89598a2d174d3bc159b3c0d837fcd28ed0c9cc2eeddcadef4be864d346a5f35c8ac3e1f4199c81f20c709155745b47da5c9dc25014384944405892af242cedb3ca2f941705e20b5a3cbf9b9a594589b60342e575eefe0d026badc53ab267708166a59a36a89691bf04cab8a76e5293cdf3bb44f932a7fef82f8be897e2277e0a92c62a61630db0e09fae1c79359a023008d4f9ad3b6b6618a1f9009783e2540b03bb244f7c21f331bd46197345dad3fd60ec8be173fb2060f6a7141bb4020dced6d2a6388b4426acf17338c619afe59a1a203dd83e8e3b38c4cc4722696fa41e478ba53c00c0bbe38673fc23dbc09e0001cf6399f157e23287b012ded502e818fc05495736d5d18af6ede793190770b406bed5fd93b7bcd417bcd5ba3ff3f941e9d7f172c624d063f7e8e830ad57a17b455f1f7e870a6bdc69d72fe813113835408aefadc29e6bd">
</form>

Is the form and the test contains:

$I->canSee('Pay Now');
$I->click('Pay Now');

The canSee is successful, however the click fails. I've tried converting the button to an input and various other things including click by selector but to no avail. The HTML validates with no serious errors.

Ideas?

5
in my case i added a 2 sec wait and it worked, eventhough codeception was also seeing the button.. which is weird - Robert Sinclair

5 Answers

1
votes

The built-in class is waitForElementClickable($element, $timeout)

For me that also didn't work, I tried scrolling to the element, waiting for it to be visible etc etc but in the end only waiting a few seconds made it work.

Also sometimes modal windows block the button so you need to wait for them to load, a pretty comprehensive piece of code is here https://gist.github.com/pastuhov/43674b195dc293ffd847

0
votes

Since you are using an ID on the button, you can use the ID to perform the click:

$I->click('#sagepay_submit');
0
votes

I was having a similar problem. In fact, none of my CSS selectors seamed to be found in codeception.

Edit your acceptance.suite.yml and change the browser property to:

browser: googlechrome

Next, go to: https://sites.google.com/a/chromium.org/chromedriver/downloads and download the latest chrome driver.

Extract it into your system path.

Then re-run your acceptance test... clicks should now work!!!

Hope this helps!!!

0
votes

Try using XPath syntax to access the button. canSee() just looks to see that the text you are looking for appears on the screen, but buttons sometimes can't be found by inserting the text that it shows on the page, in this the text 'Pay Now'. Try this:

$I->click("//button[@id='sagepay_submit']");

This is using XPath, which you can take a look at here: http://www.w3schools.com/xpath/

There is also a quick description of using XPath locators on the Codeception Acceptance Test documentation.

0
votes

For buttons without ID properties, you can also use the button name property:

$I->click('button[name="submit-button"]');