Reputation: 40881
If I have a link:
<a href="/somewhere">Click Me</a>
I know I can clickLink
based on its text.
public function testCanClickLink()
{
$this->browse(function ($browser) {
$browser->visit('/welcome')
->clickLink('Click Me');
});
}
But how can I click an icon link?
<a href="/somewhere">
<i class="fa fa-plus" aria-hidden="true"></i>
</a>
Upvotes: 10
Views: 8453
Reputation: 1440
I had the same doubt... and worst, I couldn't use href as a reference to clickable element because I just needed to open a modal. So, my solution was use the dusk attribute, like this:
<a dusk="link-click-me" href="">
<i class="fa fa-plus" aria-hidden="true"></i>
</a>
And... in my test code, run this line:
$browser->click('@link-click-me');
Enjoy! o/
Upvotes: 0
Reputation: 338
You can target the href like this:
->click('a[href="/somewhere"]')
Upvotes: 9
Reputation: 40881
This is a bit hacky, but it's what I've come up with as a workaround.
Put an id selector on the link.
<a id="link-click-me" href="/somewhere">
<i class="fa fa-plus" aria-hidden="true"></i>
</a>
Assert it's visible.
Assert path is correct.
public function testCanClickLink()
{
$this->browse(function ($browser) {
$browser->visit('/welcome')
->assertVisible('#link-click-me')
->visit(
$browser->attribute('#link-click-me', 'href')
)
->assertPathIs('/somewhere');
});
}
Upvotes: 2