H
hollex2108
Hi,
I search for a method how my function detect an event while js is
carry out a loop.
I think it's not really important for a problem solving, but goodness
knows: I want to automate a web-application (GUI in html) from the
client-side. Therefor I use FireFox with xul.
I have several self defined js-objects. The object 'Main' control the
program flow. To control a dialog I use an object 'XYZDlg'. My object
'Browser' interact with a browser-control.
Now, for example, I want to extract data from a web-side (please see
what I basically write subsequent).
My problem is, that the function 'waitUntilPageIsLoaded' not work. If
I use a while-loop js never discover that the side is loaded. If I use
window.setTimeout/setIntervall instead of the loop, the function
'waitUntilPageIsLoaded' will be leaving before the side is loaded an
so the function 'getData' cause an error becaus the field with the
data exist not yet.
main.extractXYZData();
var Main = function() {
this.extractXYZData = function() {
xyzDlg.setSearchCriteria(value);
xyzDlg.search();
db.saveXYZData(XYZDlg.getData();
}
}
var XYZDlg = function() {
this.setSearchCriteria= function(pValue) {
browser.setValueByID(IDSearchField, pValue);
}
this.search= function() {
browser.clickButton(IDSearchButton);
}
this.getData= function() {
return browser.getFieldValueByID(IDResultField);
}
}
var Browser= function() {
var PageIsLoaded=false;
waitUntilPageIsLoaded() = function() {
while (PageIsLoaded==false) {
//doEvents();
}
}
listObj.onStateChange = function(aProgress, aRequest, aFlag, aStatus)
{
save(CARRIAGE_RETURN + LINEFEED +'Browser.onStateChange()');
if (aFlag & listObj.wpl.STATE_START) {
PageIsLoaded=false;
// This fires when the load event is initiated
} else {
if (aFlag & listObj.wpl.STATE_STOP) {
if ( aFlag & listObj.wpl.STATE_IS_WINDOW ) {
// This fires when ALL load finish
}
if ( aFlag & listObj.wpl.STATE_IS_NETWORK ) {
// Fires when ALL load are REALLY
over,
PageIsLoaded=true;
}
}
}
return 0;
}
myBrowserControl.addProgressListener( listObj,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW );
this.setValueByID= function(pID, pValue) {
browser.getElementById(pID).value = pValue;
}
this.clickButton= function(pID) {
browser.getElementById(pID).click();
waitUntilPageIsLoaded();
}
this.getFieldValueByID= function(pID) {
return browser.getElementById(pID).value;
}
}
I search for a method how my function detect an event while js is
carry out a loop.
I think it's not really important for a problem solving, but goodness
knows: I want to automate a web-application (GUI in html) from the
client-side. Therefor I use FireFox with xul.
I have several self defined js-objects. The object 'Main' control the
program flow. To control a dialog I use an object 'XYZDlg'. My object
'Browser' interact with a browser-control.
Now, for example, I want to extract data from a web-side (please see
what I basically write subsequent).
My problem is, that the function 'waitUntilPageIsLoaded' not work. If
I use a while-loop js never discover that the side is loaded. If I use
window.setTimeout/setIntervall instead of the loop, the function
'waitUntilPageIsLoaded' will be leaving before the side is loaded an
so the function 'getData' cause an error becaus the field with the
data exist not yet.
main.extractXYZData();
var Main = function() {
this.extractXYZData = function() {
xyzDlg.setSearchCriteria(value);
xyzDlg.search();
db.saveXYZData(XYZDlg.getData();
}
}
var XYZDlg = function() {
this.setSearchCriteria= function(pValue) {
browser.setValueByID(IDSearchField, pValue);
}
this.search= function() {
browser.clickButton(IDSearchButton);
}
this.getData= function() {
return browser.getFieldValueByID(IDResultField);
}
}
var Browser= function() {
var PageIsLoaded=false;
waitUntilPageIsLoaded() = function() {
while (PageIsLoaded==false) {
//doEvents();
}
}
listObj.onStateChange = function(aProgress, aRequest, aFlag, aStatus)
{
save(CARRIAGE_RETURN + LINEFEED +'Browser.onStateChange()');
if (aFlag & listObj.wpl.STATE_START) {
PageIsLoaded=false;
// This fires when the load event is initiated
} else {
if (aFlag & listObj.wpl.STATE_STOP) {
if ( aFlag & listObj.wpl.STATE_IS_WINDOW ) {
// This fires when ALL load finish
}
if ( aFlag & listObj.wpl.STATE_IS_NETWORK ) {
// Fires when ALL load are REALLY
over,
PageIsLoaded=true;
}
}
}
return 0;
}
myBrowserControl.addProgressListener( listObj,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW );
this.setValueByID= function(pID, pValue) {
browser.getElementById(pID).value = pValue;
}
this.clickButton= function(pID) {
browser.getElementById(pID).click();
waitUntilPageIsLoaded();
}
this.getFieldValueByID= function(pID) {
return browser.getElementById(pID).value;
}
}