Error: cannot call remote QObject function

I have a webpage that opens a popup when a button is clicked. The new popup window has another button, after clicking the popup button, my popup window closes, and the parent window reloads to a new page.

If I do not restart the parent window, I get

FAIL Error: cannot access member `evaluate' of deleted QObject
#    type: uncaughtError
#    error: "Error: cannot access member `evaluate' of deleted QObject"
#    merge: undefined
Error: cannot access member `evaluate' of deleted QObject

And if I reboot, there will not be such an error, but the casperjs script just got stuck and did not follow the next steps.

This is my requirement. I wanted to click open popup, and then again pop-ups, click the button close me. And when the parent window reloads, get the contents of the reloaded page.

Here is my code

1. Main page:

<?php

session_start();
$newPage = isset($_SESSION['newpage']) ? $_SESSION['newpage'] : "";
?>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
    setTimeout(function() {
        console.log("NEW PAGE URL = <?php echo $newPage; ?>");
        if ("<?php echo $newPage; ?>" != "") {
            location = "<?php echo $newPage; ?>";
        }
    }, 10000);
});
</script>
<button onclick="window.open('popup.php');">Click me</button>

2.popup page:

<?php
session_start();
$_SESSION['newpage'] = 'newpage.php';
echo $_SESSION['newpage'];
?>
<head>
    <title>Popup</title>
</head>
<button onclick="window.close();window.opener.location.reload();"  class="popupbutton">Close me</button>

3.New page (reload page):

<?php
session_start();
$_SESSION['newpage'] = '';
?>
<head>
    <title>Newpage</title>
</head>
This is new page.
<button onclick="location = 'index.php';" class="popupbutton">Go back</button>

, https://github.com/n1k0/casperjs/issues/644, . , , : .

script

var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug'
});
var popupClosed = false;
var popupOpened = false;
casper.on('popup.closed', function() {
    this.echo("POPUP CLOSED");
    popupClosed = true;
    this.log(casper.popups.length);
    this.echo("Page: " + this.getTitle());
    this.echo("URL = " + this.getCurrentUrl());
    this.then(function() {
        this.echo(this.evaluate(function() {
            return document.documentElement.innerHTML;
        }));
    });
    this.open('http://localhost/sample-app/index.php');
    this.then(function() {
        this.echo(this.getPageContent());
    })
});

casper.on('navigation.requested', function() {
    this.echo("===" + this.getCurrentUrl() + this.getCurrentUrl().indexOf("newpage") > -1);
    casper.echo(this.getPageContent());
    if (this.getCurrentUrl().indexOf("newpage") > -1) {
        casper.then(function() {
            this.echo(this.evaluate(function() {
                return document.documentElement.innerHTML;
            }));
        });
    }
});

    casper.start('http://localhost/sample-app/index.php');
    casper.then(functi

on() {
    this.waitForSelector("button", function() {
        this.echo("URL = " + this.getCurrentUrl());
        this.thenClick("button", function() {
            this.echo("click to open popup");
        });
        casper.waitForPopup(/popup\.php/gi, function() {
            popupClosed = false;
            popupOpened = true;

        });
        casper.waitFor(function() {
            return popupOpened;
        }, function() {
            casper.withPopup(/popup\.php/gi, function() {
                this.echo("Popup url: " + this.getTitle() + ", " + this.getCurrentUrl());
                this.waitForSelector("button.popupbutton", function() {
                    this.click("button.popupbutton");
                }, function() {
                    this.log("No button on popup");
                });
            });
        }, function() {
            this.echo("Wait TIMEOUT");
        }, 60000);


        casper.then(function() {
            this.echo("Its here...");
            this.waitFor(function() {
                return popupClosed;
            }, function() {
                this.echo("Page: " + this.getTitle());
            }, function() {
                this.echo("TIME OUT");
            }, 60000);
        });
    }, function() {
    });
    this.log("COMPLETED");
});

casper.run(function() {
    this.exit();
});

: phantomjs -1.9 casperjs - 1.0.2.

+3
1

casperjs .

: casper.on , .

, popupClosed = true;,

casper.emit("popup.closed");

casper.emit("navigation.requested");, ( evaluate).

: casper.then casper.wait* , .

, , , . , deleted QObject .

, , , .

:

casper.waitFor(function() {
    return popupOpened;
}, function() {
    // executed at position 1
    casper.withPopup(/popup\.php/gi, function() {
        // executed at position 3
        this.echo("Popup url: " + this.getTitle() + ", " + this.getCurrentUrl());
        this.waitForSelector("button.popupbutton", function() {
            // executed at position 4
            this.click("button.popupbutton");
        }, function() {
            this.log("No button on popup");
        });
    });
}, function() {
    this.echo("Wait TIMEOUT");
}, 60000);


casper.then(function() {
    // executed at position 2
});

1: Unnest, :

casper.waitFor(function() {
    return popupOpened;
}, function() {
    // executed at position 1
}, function() {
    this.echo("Wait TIMEOUT");
    this.exit;
}, 60000);

casper.withPopup(/popup\.php/gi, function() {
    // executed at position 2
    this.then(function(){
        this.echo("Popup url: " + this.getTitle() + ", " + this.getCurrentUrl());
    });
    this.waitForSelector("button.popupbutton");
    this.thenClick("button.popupbutton");
});

casper.then(function() {
    // executed at position 3
});

EDIT: , . waitFor*, . gist, .

2: . , .

0

All Articles