0

How can I click on a simple link <a href="/some_page.html">Some page</a> via Codeception AcceptanceTester man?

class_name: AcceptanceTester
modules:
 enabled:
 - WebDriver
 - \Helper\Acceptance
 config:
 WebDriver:
 url: 'http://mysite.local'
 browser: 'firefox'
 windowSize: '1024x768'

I'm trying:

public function somePage(AcceptanceTester $I)
{
 $I->amOnPage('/');
 $I->click('Some page', '//a[href="/some_page.html"]');
}

but getting next message:

...
CSS or XPath element with '//a[href="/some_page.html"]' was not found.
...
asked Mar 17, 2017 at 10:07

4 Answers 4

2

You are using wrong xpath, it should be:

$I->click('Some page','//a[@href="/some_page.html"]');

So you are missing @ in front of href.

Just to mention if you have more links of this kind than you could access first one with this:

$I->click('Some page','(//a[@href="/some_page.html"])[1]');
answered Aug 23, 2017 at 6:28
Sign up to request clarification or add additional context in comments.

Comments

0

Is this HTML structure:

<section id="products-anchor" class="products-list">
 <div class="container">
 <ul class="products">
 ***
 <li class="">
 <h3>
 <a href="/some_page.html"> Some page </a>
 </h3>
 <p>
 <a href="/some_page.html"></a>
 </p>
 <p>
 <a href="/some_page.html">Text for some page...</a>
 </p>
 <p></p>
 </li>
 ***
 </ul>
 </div>
</section>
answered Mar 20, 2017 at 7:53

Comments

0

You can simply user Locator class here. Please check below snippet. I have used the same but using functional call. Consider that I am passing that element contains URL from my cept file.

use \Codeception\Util\Locator; Class ClassName{

public function fun_name( $strSomeVar, $selectorUrl ){

 $I->see( $strSomeVar, Locator::href( $selectorUrl ) );
 $I->click( Locator::href( $selectorUrl ) );
}

}

May be this will be helpful to you.

answered Apr 19, 2017 at 11:49

Comments

0

I'm not sure if you have to indicate the h3, but I'm pretty sure this will work.

$I->click(['xpath'=> '//ul/li/h3/a[@href="/some_page.html"]']);
Adriaan
18.2k7 gold badges48 silver badges88 bronze badges
answered Nov 3, 2017 at 6:43

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.