I want to capture the console logs & JS exceptions for each visited pages.
I tried something like this:
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability('loggingPrefs', array('browser'=>'ALL') );
then
$logs = $driver->manage()->getLog("browser");
file_put_contents("logs.txt",print_r($logs,true));
I got a log of useless logs, but can't get the real console.log.
after several hours reading in the java world, I am wondering now if the reason was not that there's actually some missing API in this driver?
Ok, I've found a hack outside faceook/php-webdriver
Can you share the hack? I'm running into the same issue where I need to access console.log in the browser
@boussou and @NoodlesNZ got any solution for this? I'm getting empty log even though I specifically executed console.log for the purpose of trying to fetch it.
Hi @NoodlesNZ & @deleugpn sorry I missed the notification from Github.
nowadays, I moved away from PHP, but from what I remember, the trick was to inject some javascript wrapper via selenium.
I'll try to find a usable code to share.
I was able to note that console.log won't be caught by WebDriver, but any actual Javascript error will. So I called an undefined function to achieve the tests I was performing.
Sorry, I never found a solution for this.
Most helpful comment
Can you share the hack? I'm running into the same issue where I need to access console.log in the browser