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>
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'); }); }
您可以像这样定位href:
->click('a[href="/somewhere"]')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.