K
K
kupurim2018-12-20 13:45:25
PHP
kupurim, 2018-12-20 13:45:25

How to wait for a page to fully load in Selenium php?

Hello.
There is a parser written in Selenium WebDriver. Link to it is here .
Initially, everything worked fine, after the changes on the site, the page began to load for a long time and the main information was loaded by Ajax. And at first, only a block with a name and a preloader.
And it turns out that not the entire html code of the page is given to me, but only the block with the preloader.
The documentation says that you can wait 10 seconds with a check interval like this:

$driver->wait(10, 1000)->until(
          function () use ($driver) {
              $elements = $driver->findElements(WebDriverBy::cssSelector('#a-match'));
              return count($elements) == 1;
          },
          'Error element'
        );

But nothing happens, the script runs for ~10 seconds and throws an "Error element" error, and it turns out that it couldn't find the right block.
How can this issue be resolved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2018-12-20
@EreminD

where you configure the driver, set the wait ( read )
Not strong in php, but you need something like this:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
So you set the time for the driver to wait for your condition to be met (if the condition is met earlier, get it earlier) . The
next question is how long are you willing to wait (sometimes people set 60 seconds).

G
grinat, 2018-12-21
@grinat

If there are Ajaxes, then just like this: $driver->wait(10, 1000)->until(
WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id('first_name'))
);
that is, you have to wait until a certain element reappears, or until the preloader disappears after Ajax, and then what to do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question