Skip to content

webdriver.executeScript wait a long time(26s) before page load #2

@huan

Description

@huan

It seems that webdriver always wait browser window to be stable before run executeScript.

the condition of stable is set to be like this:

window.document.readyState === 'complete'

But...

If we have a ajax call / http long pulling / etc, the readyState will be interactive for a long time.

Solution(?)

make webdrive wait only for readyState is loading

See Also

  1. How to executeScript before page load by WebDriver in selenium? https://stackoverflow.com/questions/37071807/how-to-executescript-before-page-load-by-webdriver-in-selenium
  2. A ghost driver on phantomjs quick & dirty patch https://github.com/detro/ghostdriver/issues/334#issuecomment-41361564
  3. Attempt to make selenium tests more reliable https://github.com/18F/calc/pull/267
  4. PhantomJS 1.9 has introduced resourceTimeout

PhantomJS Log

When waiting, it output lots of logs like this:

[DEBUG - 2016-08-07T10:21:57.754Z] Session [b69451a0-5c88-11e6-bed4-fb6eca6b39c0] - _execFuncAndWaitForLoadDecorator - Page Loading in Session: true

PhantomJS Code

Do not know what SIGNAL is, what SLOT is...

https://github.com/ariya/phantomjs/blob/096d0da87ee6d94f3eed84446c0eb5176566d54a/src/webpage.cpp#L396

GhostDriver Code

https://github.com/detro/ghostdriver/blob/f976007a431e634a3ca981eea743a2686ebed38e/src/session.js#L233

maybe change _isLoading() to this?

    /**
     * Is any window in this Session Loading?
     * @returns "true" if at least 1 window is loading.
     */
    _isLoading = function() {
        var wHandle;

        for (wHandle in _windows) {
//            if (_windows[wHandle].loading) {
            if (_windows[wHandle].document.readyState) === 'loading')
                return true;
            }
        }

        // If we arrived here, means that no window is loading
        return false;
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions