javascript - 即使在casperjs中assertExist为true也找不到元素

标签 javascript jquery html casperjs

在我的应用程序中,我遇到了 casperjs 中的问题。

我正在执行的步骤如下。

1)首先我进行断言,无论元素是否存在。

casper.then(function() {
    this.test.assertExists(
            { type: 'xpath', path: '//header[@id="masthead"]/section[3]/div/div/nav/ul[1]/li[2]/a[1]' },
            'the element exists'
    );
});

输出:通过

2) 单击该元素

casper.then(function() {
    this.click(x('//header[@id="masthead"]/section[3]/div/div/nav/ul[1]/li[2]/a[1]'));
    this.echo('clicking product and services enter code here page');
});

输出:点击产品和服务页面

3)捕获图像。

casper.then(function() {
    this.echo("Capturing image website");
    this.capture('images/po/productServices.png', {
            top: 0,
            left: 0,
            width: 0,
            height: 0
    });   
});

输出:当单击该元素时,图像没有包含我想要的内容。

请帮我解决这个问题。

谢谢, 纳拉赛亚 p

最佳答案

尝试在此处指定宽度高度:

width: viewport.viewport.width,
height: viewport.viewport.height

而不是:

width: 0,
height: 0

关于javascript - 即使在casperjs中assertExist为true也找不到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23078353/

相关文章:

javascript - PhoneGap 应用程序的 XMLHttpRequest POST 数据丢失

javascript - 高效的 jQuery 或 HTML5 图像 slider

javascript - 修改 MongoDB 以允许跨源请求

jquery - 使用JQuery slice()和appendTo()显示另一个div中的数据

带有事件类的 jQuery 切换

javascript - 单击时将嵌套数组/对象值显示到单独的元素中

javascript - 如何在 CONTENT css 中使用 href?

javascript - AJAX 调用中的强制 Document.write

javascript - 如何使用javascript动态更改文本

javascript - React 处理组件间的交互状态