phpcodeceptionacceptance-testingacceptance

Codeception acceptance tests exactly the same buttons in different forms on the same page


I have two exactly the same buttons in two different forms on the same page. Forms and buttons have no id or name and the only difference is between those forms, which is the action.

<form class="form" method="post" action="http://mysite/one">
    <button title="" type="submit" class="button">Edit</button>
</form>

<form class="form" method="post" action="http://mysite/two">
    <button title="" type="submit" class="button">Edit</button>
</form>

I am writing acceptance tests in Codeception and perform those tests using PhpBrowser.

I want to click those buttons but only the first one is clicked.

This works only for the first button:

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



Solution 1:
I added IDs to the buttons.

Solution 2:

$I->click("//form[contains(@action,'http://mysite/two')]/button[@type='submit']");

Solution

  • Try something like the following:

    $I->click("//form[contains(@action,'http://mysite/two')]/button[@type='submit']");