It may be that you have multiple links on a page, all with the same text, but different href's. For example, you have something like this in a table:
<a href="items/1/edit" class="btn">Edit</a>
<a href="items/2/edit" class="btn">Edit</a>
Currently (unless I am missing something), it is not possible to select which of these links you want to click.
The seeLink() method can specify which href you want to target (seeLink('Edit', 'items/1/edit)`, but I can't see a way to specify a more precise click
$I->click('Edit','a[href="items/1/edit"]') ?
Research XPaths and CSS selectors, both can achieve what you are wanting and I always use them rather than simply the text that appears on the button. You can use them in place of your previous selector without any further changes needed (see comment above by Ragazzo)
Sorry, It took some time to get here.
My suggestion is to specify the context of a click.
For your case it looks like you have a table with "Edit" link for each row.
Probably you can do:
$I->click('Edit','tr#item2');
Where you specify the row you need in second argument.
Codeception does not have option to click the link by its href because, as a user you don't scan a page for all hrefs, you click links, based on their names and position. Thus, more cleaner way is to specify the context of a link.
OK, but this is confusing when method seeLink()
I see link "a","/promotion/update?id=1" ~OK
works and click()
I click {"link":"/promotion/update?id=1"} ~not found on page
I click "//a[@href='/promotion/update?id=1']" ~not found on page
I click "a[href='/promotion/update?id=1']" ~not found on page
doesn't...
Hmm, so in Yii2, when use GridView and want to click "update icon" only way is something like this:
$I->click("//td[text()='Unique-record-name']/following::td[last()]/a[@title='Update']");
To find table row by record name, then go to last table column (\yii\grid\ActionColumn) and then find update icon? :|
What does one do if they have this:
<a href="/site/index"><span class="glyphicon glyphicon-home"></span> Home</a>
@jairusmartin Have found any solution for that. I am currently looking for it.
@DavertMik can you check that please?
It appears the search text must match exactly after the tags have been removed.
Like this: I->click(' Home')
In short, for test ability, it is better to use CSS for appearance and not use white space characters.