Search code examples
phpseleniumautomationwebdriver

PHP Webdriver interact with the DOM before the page finishes loading


When using PHP webdriver, whenever I call $driver->get(), I have to wait for the page to fully load, before I can interact with it. I tried setting a timeout, catching the exception and trying to access the browser from there. But it does not work.

The DOM is interactive though, you can start interacting with it manually, so is there a way to interact with it before the page is fully loaded.

I'm using PHP 7.2 & PHP 8 (same result) Latest version of PHP WebDriver Firefox 102 Selenium Standalone 3.41.59


Solution

  • I tried the following and it worked:

    $driver->get('about:blank');
    $driver->executeScript("window.location.href = 'https://whatever.com'");
    // You can start interacting immediately
    

    I hope this helps somebody