0
votes

I'm using Laravel 5.8 - Dusk.

I'd like to know how can I perform a right click on each element when iterating through them in the following example:

$browser->visit('https://www.website.com')
        ->script('window.scrollTo(0, 10000);');

$elems = $browser              
          ->pause(1000)
          ->elements('.selectable');

foreach ($elems as $elem) {
   $elem->rightClick(); // this does not work
}

Is it possible to perform a right click OR drag event on each of the elements? I basically want to perform any action on the element, because javascript changes an attribute on the element if it's being clicked, dragged, etc.

1
@JonasStaudenmeir Yep, seen. I've also looked into the files and found the rightClick method, but can't use it when iterating through the elements for some reason.Radical_Activity

1 Answers

2
votes

You can use the code from the rightClick() method:

foreach ($elems as $elem) {
    (new WebDriverActions($browser->driver))->contextClick($elem)->perform();
}