How to prevent Selenium from loading js file?

The title pretty much sums it up.

I have a website that hosts a custom js file and in order to write some tests I need to disable the loading of that js file, but add your js file instead. Using a function execute_script

from Chromedriver

. And here I am not sure about the working approach.

I was thinking about adding rules in addition to NoScript, which will prevent the first js file from loading, disable it and inject my js file, but I'm not sure when this is possible.

+3


source to share


1 answer


Selenium is for end-to-end testing. If you need to change the content of the page, you may be using the wrong tool.

It is possible to modify the page with Selenium using a JavaScript snippet via executeScript

. However, this can only be done after the page has fully loaded, and possibly after the original script has been executed.



One way is to use a proxy to intercept the resource and redirect another.

+1


source







All Articles