casper.waitForAlert(function(response) {
this.echo("Alert received: " + response.data);
});
5000 毫秒的等待超时已过期,正在退出。//无论警报是否存在,我都希望代码继续并存储在变量中
例如...如果(exists.alert)..{} :-(
最佳答案
基本上,您应该为 waitForAlert 函数使用 onTimeout 选项。 如果我们在外部(全局)定义 myAlert 变量,那么您可以在任何地方使用它。此外,通过使用对象,我们还有一个优势,即我们可以轻松保存例如警报值
var myAlert;
casper.waitForAlert(
function(response) {
myAlert = { exists:true, value:response.data };
},
function() {
myAlert = { exists:false };
});
casper.then(function() {
if ( myAlert.exists ) {
this.echo( "Alert exists and value is: " + myAlert.value );
} else {
this.echo( "Alert doesn't exists" );
}
});
关于javascript - 我如何评估 casperjs 中是否存在警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42907131/