[Selenium - Java - Chrome 103] Slow data transfer in "executeScript"

64 views
Skip to first unread message

Arseniy K

unread,
Jul 8, 2022, 9:42:41 AM7/8/22
to Selenium Users
Hello. I noticed a peculiarity in working with JavaScript.
Code execution:
    JavascriptExecutor js = (JavascriptExecutor)driver;
    response = (String) js.executeScript("return \"111\";");
takes less than 1 second.
But 
    response = (String) js.executeScript("return \"{string 5 000 000 +}\";");
takes more than 5 seconds.

That is, when executing code similar to
    response = (String) js.executeScript("return document.documentElement.outerHTML;");
where pages are larger than 10 MB, most delays occur. Are there options to fix this?

David

unread,
Jul 11, 2022, 10:42:29 PM7/11/22
to Selenium Users
Curious to wonder whether this issue is specific to the Javascript executor. If you executed similar code in the browser developer/javascript console, will it take a while or that is instantaneous? Perhaps with respect to the outerHTML example running something like 

var response = document.documentElement.outerHTML;

and then just dumping the value in the console

maybe is an issue with the typecasting or JS engine interface if the issue is Selenium specific.

If it is fast in javascript (console), there is a possible workaround you can try in the meantime. Do more of the logical data processing within Javascript that you are executing, encapsulating code in javascript function(s) and calling the (chain of?) function(s) instead. Once you've filtered down the data to a more smaller or simplified subset, then you can return that back to Selenium. For example, if you process the outerHTML to extract certain text and only need a small subset of the actual complete page, maybe faster to do in JS then return to the calling language code than to do it in the language you're using Selenium with. Worth an experiment. If workaround is no faster, then something is obviously strange with JavascriptExecutor behavior.
Reply all
Reply to author
Forward
0 new messages