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.
...
4 Answers 4
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]');
Comments
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>
Comments
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.
Comments
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"]']);