Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laracoft's avatar

Click only 1 button

// pestphp/pest 4.1.0
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Pest\Browser\Api\AwaitableWebpage;

test('example', function () {
    $page = visit('https://example.com')
        ->press('Get tickets');

    $page->withinFrame('.iframe-container', function (AwaitableWebpage $page) {
        $page->press('Register'); // clicks both Register buttons
    });
});

The iframe has 2 buttons with "Register" as text (which I cannot rename), how do I pick only 1 and click it?

0 likes
2 replies
tisuchi's avatar

@laracoft How about you define one button inside a unique wrapper?

$page->within('.form-container', function ($form) {
    $form->press('Register');
});

This ensures only the button inside that container is clicked.

Snapey's avatar

which I cannot rename

Is that because you are trying to use Pest to automatically purchase tickets on someone else's ticketting website?

I don't think I want to help you do that..

1 like

Please or to participate in this conversation.