Thursday, April 13, 2017

How to use Laravel Dusk with Gmails dynamic selectors

I'm struggling to get consistent results using Laravel Dusk to send emails via logging into Gmail and navigating to the "COMPOSE" button since the elements ID and class is being dynamically changed on page reload.

I have tried using inspect element and copying the selector with no luck.

The purpose of this exercise is just to get a better understanding of Laravel Dusk and have some fun while going about it.

My code below:

    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('#\3a xy > div > div', 10)
        ->click('#\3a 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
    });
}

Any help will be greatly appreciated.



via Devin Norgarb

Advertisement