I’m doing a FireFox extensions. I have an array of URL’s. What I want is: redirect the page with document.location.href for all the URL’s that I have and then, with a XPath that I have, count the number of elements that the page has.
The problem is that I have to wait that the page load was finish before execute the count method with the XPath. This is my code:
var actualResult = 0;
actualResult = content.document.evaluate('count('+taskModeler.ui.getStatus()+')', content.document, null, XPathResult.NUMBER_TYPE, null).numberValue;
for(var i=0; i<taskModeler.ui.getPageContent().length;i++) {
content.document.location.href = taskModeler.ui.getPageContent()[i].getAttribute("href");
//only if the page was loaded execute the next line
actualResult+=content.document.evaluate('count('+taskModeler.ui.getStatus()+')',
content.document, null, XPathResult.NUMBER_TYPE, null).numberValue;
}
getPageContent() returns an array that contains a set of URL’s. For each of these URL’s I have to load the page to get acces to the document and then count the occurrences that returns the XPath. But if the page not was loaded the count method doesn’t work because returns the results of the actual page, not the page that was loaded in content.document.location.
How can I do that?
you need to use progress listener read this
if u need more help tell me.