Python Selenium execute_script jQuery Error and Discrepencies Between OSs

I’m using Selenium with Python (3.5) to programmatically explore a site. One step of this exploration includes scrolling to the bottom of a given page, and I have chosen to do so with jQuery as such where driver is the webdriver object and scrollloadtime is the set amount of time I want the scrolling to take:

driver.execute_script("$('html, body').animate({scrollTop: $(document).height() - $(window).height()}, %s);" % scrollloadtime)

This is where things get weird. When I run this code in a test environment (VM running Kali Linux), I have no issues with this — I’ve never once had a problem with this line running in this environment.

However, when I attempt to run the exact same code with the exact same package versions (which I have listed below) on the exact same webpage inside a docker container running Debian Stretch, I get the following error:

Message: TypeError: $(...).animate is not a function

I’d like to figure out why this is happening rather than just a workaround. It’s driving me insane!

I’m certainly no jQuery expert, but from the research I’ve done on the above error this normally occurs when either an old and minimized jQuery version is being used. What I can’t figure out myself is how that solution then ties into Selenium or even Python itself.


Things I have tried, to no avail:

  • Installed jquery-related packages that exist on my test environment that did not exist within the docker image, on the docker image (i.e. all libjs-jquery* packages).

  • Attempted to inject jQuery into the page before running the script which triggers DDoS security. (Additionally, this shouldn’t be necessary because the jQuery script worked without any injection in the test environment)

  • Attempted to exchange the initial $('html, body') with a defined variable (var x = document.getElementsByTagName('html')[0]; x.animate(...), though I will be the first to admit that I might not have done so correctly


Versions:

  • Python 3.5

  • Selenium (Python) 3.141.0

  • Geckodriver 0.24.0

  • Firefox ESR 68.1.0

  • Debian Stretch and Kali Linux


Any assistance or troubleshooting guidance would be greatly appreciated. Let me know if I can provide any additional information.

Source: StackOverflow