Reputation: 8937
Followed the start guide, I can run a javascript snippet by using driver.execute(). How can I run external javascript files, which load some external modules itself.
Possible ways I can come up with:
Concatenate all required files into a single large file and then load it into a string and run it with driver.execute(). Possibly with help of a minifier.
Execute a small snippet to load all required js files.
Maybe modify the html before browser render it?
Any suggestions?
Upvotes: 1
Views: 7863
Reputation: 473873
You can actually load scripts dynamically via execute_script()
. Here is an example use case where jquery
library is dynamically loaded to support HTML5 drag&drop simulation:
The key functionality is the javascript code that is executed via execute_async_script()
(taken from here) that adds a script
element to head
via document.createElement()
on the fly.
The first link has a working example in Python, the second one has it in Java.
Upvotes: 1