等待CasperJS的多个替代select器

我有一个应用程序,可以对我的CasperJS脚本的行动有不同的反应,所以我需要同时等待不同的select器,并根据第一个匹配的select器。 但是,看起来CasperJS一次只能等待一个select器。

我如何等待不同的反应,并将脚本的执行转移到不同的分支?

您可能想尝试等待组合select器(CSS逗号分隔的列表充当逻辑or ),然后检查每个select器(如果它存在于页面和分支中),沿着这个(未经testing的)伪代码的行:

 var selectors = [ '.my.first .fancy .selector', '.boring' ]; casper.waitForSelector(selectors.join(', '), function(){ var idx; for (idx = 0; idx < selectors.length; ++idx) { if (casper.exists(selectors[idx])) { doSomething(idx); } } });