2014-04-15 16 views
0

在我的應用程序中,我遇到了casperjs中的問題。在casperjs中找不到元素即使assertExist爲true

我正在做的步驟如下。

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

回答

1

嘗試指定widthheight此處的

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

代替:

width: 0, 
height: 0 
1

嘗試使用等待指令-waitForSelector,waitForUrl,waitForText。 ..-在3)點擊後:

例:

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