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

PhilKz's avatar

Selecting all elements of class {someclass} in Dusk

Is there a way of doing something like

//Assigning an array containing every input with class 'somecheckbox' to $checkboxes.
$checkboxes = $browser->getElementsByClass('input','somecheckbox');

in Laravel dusk?

"Why are you trying to do this?": I am writing a test for a page that has multiple forms on it. Each form has an "agree to privacy policy" checkbox. When the user clicks on the checkbox on any form, the privacy policy checkbox on every form is checked. So, in order to write a test, I need to be able to get an array of all the privacy policy checkboxes on the page, then assert that each of them is checked. i.e.

foreach($checkboxes as $checkbox){
		$browser->assertChecked($checkbox);
}

These forms are part of a component that can appear an unpredictable number of times on a page, so going through each and giving them a dusk selector or an ID would make maintaining the test and the site a huge pain.

0 likes
2 replies

Please or to participate in this conversation.