php – Laravel Dusk NoSuchElementException /无法找到元素

我正在尝试运行一些基本的Laravel Dusk测试,但总是遇到Facebook WebDriver的问题:

我已将chrome更新到最新版本,并使用Hombrew手动更新了Chrome WebDriver:

有什么建议?

干杯,斯坦

错误:

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>
最佳答案
我希望你此时已经解决了这个问题.根据Laravel Dusk documentation

although the method accepts one if necessary, we are not required to pass a CSS selector into the type method. If a CSS selector is not provided, Dusk will search for an input field with the given name attribute. Finally, Dusk will attempt to find a textarea with the given name attribute.

看看你的错误,好像你传递了错误的选择器.尝试使用输入字段的名称,如下所示

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

转载注明原文:php – Laravel Dusk NoSuchElementException /无法找到元素 - 代码日志