Click Me I know I can clickLink based on its text. pu...">

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> 
+5
source share
2 answers

You can target href as follows:

->click('a[href="/somewhere"]')

+2
source

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'); }); } 
+3
source

Source: https://habr.com/ru/post/1264744/


All Articles