I a have a file in php 7+ with this head

<?php
    require __DIR__.'/vendor/autoload.php';

    use Facebook\WebDriver\Interactions\WebDriverActions;
    use Facebook\WebDriver\WebDriverBy;

    try {

        $arguments = [
            "--no-sandbox",
            "--disable-gpu",
            "--headless"
        ];

        $options = [
            'download.default_directory'  => '/tmp',
            'window-size'=>'1024,768',
           'profile.managed_default_content_settings.cookies'=>1,
        ];
    
        $client = \Symfony\Component\Panther\Client::createChromeClient('',$arguments,$options);
        //... read every link in front page
        //...for to click in each link
        // pass the page where the url is
        $actioWebObj= new WebDriverActions($pantherCrawlerObj->WebDriver());    
        //  pass the url to click
        $actionWebObj->movetoElement($remoteWebElementObj);
        //... write in a csv file  html data of the visited page

This code functions OK and I have all the data server page I need in a csv. Now, I have try to pass this code to laravel 8, to a class I put the code in App/Classes/ReadWebClass.php

<?php
    namespace App\Classes;

    use Symfony\Component\Panther\Client;
    use Facebook\WebDriver\WebDriverBy;
    use Facebook\WebDriver\Interactions\WebDriverActions;

    class ReadWebClass{

        /**
        * read all the web and save to the ddbb
        * @return void
        */ 
        static function readWeb(){
            //
            try{
                $arguments = [
                    "--no-sandbox",
                    "--disable-gpu",
                    "--headless"
                ]; 
                $options = [
                    'download.default_directory'  => '/tmp',
                    'window-size'=>'1024,768',
                    'profile.managed_default_content_settings.cookies'=>1,
                ];

                $client = Client::createChromeClient('',$arguments,$options);
                //... read every link in front page
                //for to click in each link
               // with a dd I have the same list of link with the simple php code
               $actioWebObj= new WebDriverActions($pantherCrawlerObj->WebDriver()); //(<-throw error) 
               $actionWebObj->movetoElement($remoteWebElementObj);
          

In laravel the $th from cath shows me: "Call to undefined method Symfony\Component\Panther\DomCrawler\Crawler::WebDriver()" In the debuger of CVCode the $pantherCrawlerObj is a object of the Symfony\Component\Panther\DomCrawler\Crawler class and has the correct data. I have used the composer to install all and it send me ok .

0

There are 0 best solutions below