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

Element is not found even assertExist is true in casperjs

本文关键字:找不到 元素 true 中为 assertExist casperjs 即使      更新时间:2023-09-26

在我的应用程序中,我在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
    });   
});

输出:当点击该元素时,图像并不是我想要的。

请帮我解决这个问题。

谢谢,Narasaiah p

尝试在此处指定widthheight

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

而不是:

width: 0,
height: 0

尝试使用等待指令-waitForSelector、waitForUrl、waitForText…-在3)点击后:

示例:

casper.waitForSelector('the selector to wait before taking the capture', function() {
    this.capture('images/po/productServices.png');
});