How to click link icon with laravel dusk?
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 the link to the icon?
<a href="/somewhere"> <i class="fa fa-plus" aria-hidden="true"></i> </a> This is a bit hacky, but this is what I came up with as a workaround.
Put the id selector in the link.
<a id="link-click-me" href="/somewhere"> <i class="fa fa-plus" aria-hidden="true"></i> </a>Confirm it.
- Get the href attribute.
- Visit him.
The correct way to confirm.
public function testCanClickLink() { $this->browse(function ($browser) { $browser->visit('/welcome') ->assertVisible('#link-click-me') ->visit( $browser->attribute('#link-click-me', 'href') ) ->assertPathIs('/somewhere'); }); }