Scroll until the end of chrome page with javascript

Hello, I get trouble with my script. I want to scroll until the end of a chrome page to scrape data. I use DO While until the end of the page. I have made severals test and I saw that the script continue to act even if the page is at the end. There is no scroll anymore but the program still working.

Then I got an error Inject js script ‘iexplore.exe How’: Une erreur HRESULT E_FAIL a été retournée à partir d’un appel à un composant COM.

There is something wrong with my script, could someone help me please ?

Thanks in advance
Regards

Here is the script I have used :

window.onscroll = function (ev) {
    var docHeight = document.body.offsetHeight;
    docHeight = docHeight == undefined ? window.document.documentElement.scrollHeight : docHeight;

    var winheight = window.innerHeight;
    winheight = winheight == undefined ? document.documentElement.clientHeight : winheight;

    var scrollpoint = window.scrollY;
    scrollpoint = scrollpoint == undefined ? window.document.documentElement.scrollTop : scrollpoint;

    if ((scrollpoint + winheight) >= docHeight) {
        return 'True';
    }
    else
    {
	return 'False';
    }

};

Hello @aurelie.hoareau

Could you please paste your full traceback at Inject JS activity and share the parameters used in this activity?

main.xaml (19.1 KB)

window.onscroll = function (ev) {
var docHeight = document.body.offsetHeight;
docHeight = docHeight == undefined ? window.document.documentElement.scrollHeight : docHeight;

var winheight = window.innerHeight;
winheight = winheight == undefined ? document.documentElement.clientHeight : winheight;

var scrollpoint = window.scrollY;
scrollpoint = scrollpoint == undefined ? window.document.documentElement.scrollTop : scrollpoint;

if ((scrollpoint + winheight) >= docHeight) {
return ‘True’;
}
else
{
return ‘False’;
}
};

I ran it without error with “https://docs.uipath.com/activities/lang-en/docs/inject-js-script” as url. (well, it returned True at first iteration)

I changed your script by editing the comparison from >= to < and inserting an alert to display the three values. After the delay, if the modal window is still displayed, I’ve got the same error message.

I’d say that something is preventing access to your target element.

@aurelie.hoareau
welcome to the forum
the bes results with inject js was when we still follow the conventions as described by the docu:


especialy on
element - represents the HTML element corresponding to the calling UI node.
input - the input string provided by the caller. 

also if no ui element is to use we passed it as null for tests, then for other tests we removed in scond round

Additional we checked very carefully the selector of the invike js activity that it is pointing to page of interest just to prevent that the javascript is send to Nirvana

1 Like

Ok, thanks for your response !

Ok, thanks for your response ! I am going to check the convention.