ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-PhantomJS / CasperJS AssertExists()失败

2019-11-21 19:49:36  阅读:267  来源: 互联网

标签:phantomjs jquery-selectors casperjs javascript jquery


我正在尝试检查网页中是否存在选择器,但是casperjs找不到它.

我尝试了两种方法:

1.不用等待

casper.then(function() {
    // search for 'casperjs' from google form
    this.test.assertExists('#search-form', 'the element exists');
    // this.test.assertExists('.glyphicon.glyphicon-plus', 'the element exists');
});

2.等待选择器

casper.waitForSelector('#search-form', function() {
    this.echo("I'm sure #search-form is available in the DOM");
});

3.另一种等待方法

casper.waitFor(function check() {
     return this.evaluate(function() {
         return $('#search-form').length == 1;
     });
 }, function then() {    // step to execute when check() is ok
     test.assertExists('#search-form', 'tabs area is found');
 }, function timeout() { // step to execute if check has failed
     this.echo("Timeout: page did not load in time...").exit();
 });

到目前为止,他们还没有找到选择器.并且此选择器是从html加载的,不是由javascript插入的.

有任何想法吗?

解决方法:

好吧,我认为您应该检查选择器是否在您的网页中,例如:

casper.then(function(){
    console.log(this.getPageContent());
});

命令-pipe输出-:casperjs测试yourFile.js> seePageContent.html

或者,您可能更喜欢这种方式(如果需要,请稍候):

casper.then(function(){
    this.wait(3000,function(){
        var fs = require('fs');
        fs.write("seePageContent.html", this.getPageContent(), 'w');
    });
});

这样,您就知道您的元素是否存在.如果不是,则您的上一步是错误的.

标签:phantomjs,jquery-selectors,casperjs,javascript,jquery
来源: https://codeday.me/bug/20191121/2054111.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有