Search code examples
seleniumxpathcodeceptionacceptance-testing

Codeception: I can see a link, but can't click it


I am working through learning Codeception, and have run into something I think is strange.

// This works
$I->see('Secure Check Out', '(//a[contains(text(),"Secure Check Out")])[2]');

// This does not
$I->click('Secure Check Out', '(//a[contains(text(),"Secure Check Out")])[2]');

Couldn't click "Secure Check Out","(//a[contains(text(),"Secure Check Out")])[2]": Link or Button or CSS or XPath 'Secure Check Out' was not found on page.

Running against Firefox via Selenium WebDriver. What do I have to do to get this to work?

Here's roughly the HTML that's relevant.

<div class="mobile-only">
<a href="/responsive/ajax/modals/check-out/login.php" class="secure-checkout button blue bordered small modal-open">Secure Check Out</a>
</div>

<div class="secure-checkout-button threecol last mobile-hide">
<div class="pull-right">
<a style="background-color: transparent;" href="/responsive/ajax/modals/check-out/login.php" class="button blue bordered small modal-open">Secure Check Out</a>
</div>
</div>

Solution

  • Seems like it's just because the see function allows two parameters and click does only one in case of xpath. So, according to this the following should work

    $I->click('(//a[contains(text(),"Secure Check Out")])[2]');