我有一个网页,点击一个按钮后会打开一个弹出窗口。新的弹出窗口有另一个按钮,当点击弹出按钮我弹出关闭和父窗口重新加载到新页面。错误:无法调用已删除的QObject函数
如果我不重装我的父窗口,我得到
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
如果我重装,有没有这样的错误,但casperjs脚本只是卡住,不执行进一步的步骤。
这是我的要求 我想点击open popup
,然后弹出加载后再次单击close me
按钮。当父窗口重新加载时,获取重新加载页面的内容。
这里是我的代码
1。主页:
<?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页:
<?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页面(重装页) :
<?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,但没有奏效。所以,我将代码修改为如下:这不是没有给出预期的结果。
卡斯帕脚本
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。