栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

具有链接选择的CasperJs和Jquery

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

具有链接选择的CasperJs和Jquery

这是我的方法。因为Web上下文包含jQuery,所以我们可以使用它来触发事件,并且重要的一步是,在每个ajax调用之后,我们必须等待并验证,然后才能处理任何下一步。

//set select valuesvar optionFirstSelect  = 125;var optionSecondSelect = 6;    var optionThirdSelect  = 47;//create casper objectvar casper = require('casper').create({    loadImages:false,    verbose: true,    logLevel: 'debug'});//open urlcasper.start('http://thewebsite.com');casper.then(function(){    //select option on first select    this.evaluate(function(valueOptionSelect){        $('select#s1').val(valueOptionSelect);        $('select#s1').trigger('change');    },optionFirstSelect);    //wait until the second select is populated    this.waitFor(function check() {        return this.evaluate(function() { return document.querySelectorAll('select#s2 option').length > 1;        });    }, function then() { //select option on second select this.evaluate(function(valueOptionSelect){     $('select#s2').val(valueOptionSelect);     $('select#s2').trigger('change'); },optionSecondSelect); //wait until the third select is populated         this.waitFor(function check() {     return this.evaluate(function() {         return document.querySelectorAll('select#s3 option').length > 1;     }); }, function then() {         //select option on third select         this.evaluate(function(valueOptionSelect){  $('select#s3').val(valueOptionSelect);  $('select#s3').trigger('change');         },optionThirdSelect);         //wait until table with info is populated after an option is seleted on third select.          this.waitFor(function check() {          return this.evaluate(function() {   return  document.querySelectorAll('table#info tbody tr').length > 1;          });      }, function then() {      //Do verifications here ...         });     });  }); });casper.run(function() {    //finish execution script     this.exit();});


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/393447.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号