Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JavaScript to get the text of an element using Laravel Dusk

I'm doing automated testing using Laravel Dusk, when I do this:

$test = $browser->script('$(".page-sidebar-menu").text();');
dd($test);

It returns array of null, but if run $(".page-sidebar-menu").text(); in a browser, it returns all text inside that class.

Where I go wrong in here? Please help if you know.

like image 327
Felix Prawira Azali Avatar asked Jan 18 '26 05:01

Felix Prawira Azali


1 Answers

Okay it's wrong of me to asked this, I not include return inside script it should be like this

$test = $browser->script('return $(".page-sidebar-menu").text();'); dd($test);

like image 164
Felix Prawira Azali Avatar answered Jan 19 '26 19:01

Felix Prawira Azali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!