Laravel Dusk NoSuchElementException / Unable to find item

I try to run some basic Larvel Dusk tests, but always run into problems with Facebook WebDriver:

I have already updated chrome to the latest version and manually updated Chrome WebDriver using Hombrew:

Any suggestions?

Cheers, Stan

Error:

Tests\Browser\Tests\Auth\SignUpTest::a_user_can_sign_up Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='input[name="name"]']"} (Session info: headless chrome=64.0.3282.119) (Driver info: chromedriver=2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.12.6 x86_64) 

MySignUpTest:

 public function a_user_can_sign_up() { $this->browse(function (Browser $browser) { $browser->visit(new SignUpPage) ->signUp('Erika Musterfrau', ' erika.musterfrau@socialite.ch ', 'password', 'password') ->assertPathIs('/dashboard') ->assertSeeIn('.navbar', 'Erika Musterfrau'); }); } 

MySignUpPage:

  public function assert(Browser $browser) { $browser->assertPathIs('/register'); } public function signUp(Browser $browser, $name = null, $email = null, $password = null, $passwordConfirmation = null) { $browser->type('@name', $name) ->type('@email', $email) ->type('@password', $password) ->type('@password_confirmation', $passwordConfirmation) ->press('Register'); } /** * Get the element shortcuts for the page. * * @return array */ public function elements() { return [ '@name' => 'input[name="name"]', '@email' => 'input[name="email"]', '@password' => 'input[name="password"]', '@password_confirmation' => 'input[name="password_confirmation"]', ]; } 

OneOfMyRegisterInputViews:

 <div class="form-group row"> <div class="col-lg-8 offset-2"> <input placeholder="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required > @if ($errors->has('name')) <div class="invalid-feedback"> <strong>{{ $errors->first('name') }}</strong> </div> @endif </div> </div> 
+7
source share
2 answers

Hope you have solved this problem by now. According to Laravel Dusk Documentation

although the method accepts it, if necessary, we do not need to pass the CSS selector to the type method. If no CSS selector is specified, Dusk will look for an input field with the given attribute name. Finally, Dusk will try to find the text field with the specified attribute name.

Looking at your mistake, it seems that you are passing the wrong selector. Try using the name of the input fields as shown below

 $browser->type('name', $name) ->type('email', $email) ->type('password', $password) ->type('password_confirmation', $passwordConfirmation) ->press('Register'); 
+1
source

For those who still have a problem: check the APP_URL variable in your Laravel.env file. The URL at which the application runs must match the APP_URL parameter

0
source

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


All Articles