Answer the question
In order to leave comments, you need to log in
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"}
Route::get('/baseavtolist', [BaseavtoController::class, 'baseavtolist'])->name('bases.list');
Route::get('/baseavtocreate', [BaseavtoController::class, 'baseavtocreate'])->name('bases.create');
//страница для просмотра баз авто
public function baseavtolist()
{
return view('baseavtolist');
}
class AddBaseavtoTest extends DuskTestCase
{
public function testAddBaseavtoSuccess()
{
$this->browse(function (Browser $browser) {
$browser->visitRoute('bases.list')
->click('#content > #add-baseavto-btn');
});
}
}
@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
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 questionAsk a Question
731 491 924 answers to any question