Z
Z
Zhenya Starikov2021-03-31 11:30:34
Laravel
Zhenya Starikov, 2021-03-31 11:30:34

Can't find Laravel Dusk link, what's wrong?

I want to master Laravel Dusk and had problems at the very beginning.
Can't find button by id on page. What am I doing wrong?
I am getting an error:

NoSuchElementException: no such element: Unable to locate element:
 {"method":"css selector","selector":"body #content > #add-baseavto-btn"}


Here is an excerpt from the content of web.php:
Route::get('/baseavtolist', [BaseavtoController::class, 'baseavtolist'])->name('bases.list');
Route::get('/baseavtocreate', [BaseavtoController::class, 'baseavtocreate'])->name('bases.create');

Here are the controller methods:
//страница для просмотра баз авто
    public function baseavtolist()
    {
        return view('baseavtolist');
    }

Here is the actual test code - I'm trying to find a button with id=add-baseavto-btn and click on it:
class AddBaseavtoTest extends DuskTestCase
{
    public function testAddBaseavtoSuccess()
    {
        $this->browse(function (Browser $browser) {
            $browser->visitRoute('bases.list')
                        ->click('#content > #add-baseavto-btn');
        });
    }
}

An excerpt from the baseavtolist view:
@section('content')
<main id="content">
  <div class="container">
        	<a class="btn btn-primary" id="add-baseavto-btn" href="baseavtocreate" role="button">Добавить</a>
  </div>
</main>
@endsection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-03-31
@delphinpro

Firstly, your button is not a direct descendant of #content, and therefore is not found. Remove the angle bracket from the selector.
Secondly, if the button has an identifier, then by definition it is the only one on the page, which means it is quite simple->click('#add-baseavto-btn');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question