如何将 Laravel Dusk 与 Gmail 动态选择器一起使用

How to use Laravel Dusk with Gmails dynamic selectors

我正在努力使用 Laravel Dusk 发送电子邮件来获得一致的结果 通过登录 Gmail 并导航到 "COMPOSE" 按钮,因为元素 ID 和 class 在页面重新加载时动态更改。

我试过使用检查元素并复制选择器,但没有成功。

这个练习的目的只是为了更好地理解 Laravel Dusk 并在实践中获得一些乐趣。

我的代码如下:

    public function testGmailExample()
{
    $this->browse(function (Browser $browser) {
        $browser->visit('http://gmail.com')
        ->assertSee('Gmail')
        ->type('Email', 'myemail@gmail.com')
        ->pause(1000)
        ->press('#next')
        ->pause(1000)
        ->assertSee('myemail@gmail.com')
        ->type('#Passwd', 'myPassword')
        ->press('#signIn')
        ->waitFor('#a xy > div > div', 10)
        ->click('#a xy > div > div')
        ->pause(1000)
        ->type('to', 'an_excited_friends_email@gmail.com')
        ->type('subjectbox','Laravel Dusk is Awesome')
        ->click('Send')
        ->pause(3000);
        //Only had one success with the above code, would prefer consistent results
    });
}

任何帮助将不胜感激。

你可以使用 clickLink() :

$browser->clickLink('COMPOSE');

来自文档:

To click a link, you may use the clickLink method on the browser instance. The clickLink method will click the link that has the given display text