minkphp / MinkGoutteDriver

Goutte driver for Mink framework
MIT License
299 stars 52 forks source link

Js evaluate error #87

Closed ghost closed 3 years ago

ghost commented 3 years ago

Code what I am used:

<?php
require_once "vendor/autoload.php";
use Behat\Mink\Mink,
    Behat\Mink\Session,
    Behat\Mink\Driver\GoutteDriver,
    Behat\Mink\Driver\Goutte\Client;
$driver = new \Behat\Mink\Driver\GoutteDriver();
$session = new \Behat\Mink\Session($driver);
// start the session
$session->start();
//Visiting link
 $session->visit("http://3.134.82.150/d_a.php");
$session->wait(
    5000,
    "document.documentElement.innerHTML"
);
// use history controls:
//$session->back();
//$session->forward();

Error what I got:

Fatal error: Uncaught Behat\Mink\Exception\UnsupportedDriverActionException: JS is not supported by Behat\Mink\Driver\GoutteDriver in C:\laragon\www\js\vendor\behat\mink\src\Driver\CoreDriver.php:449 Stack trace: #0 C:\laragon\www\js\vendor\behat\mink\src\Session.php(354): Behat\Mink\Driver\CoreDriver->wait(5000, 'document.docume...') minkphp/Mink#1 C:\laragon\www\js\index.php(21): Behat\Mink\Session->wait(5000, 'document.docume...') minkphp/Mink#2 {main} thrown in C:\laragon\www\js\vendor\behat\mink\src\Driver\CoreDriver.php on line 449
aik099 commented 3 years ago

@j311yfish , this is because a Goutte driver is a headless driver (doesn't use an actual web browser), but to wait for some JavaScript code to be executed you need a real web browser.

I recommend using the Selenium2 driver to make it work. Also, Zombie driver does support JavaScript, even though it's a headless driver.