I'm currently using Selenium WebDrivers for my tests and I'm struggling with an automatic download. The case is:
I click on a button, it loads the next page containing a script tag with a click() on a download link.

Is it possible to edit the script tag (or even delete it) before the full page loading, and avoiding this click and so, the automatic download ? I want to manually download it. It permits me to have one single solution, and not one auto download disable configuration for each browser .....

Thanks a lot !

1 Answer 1


Yes. You can execute Javascript like so. Of course, implementation may vary depending on the language you're using.

WebDriver driver = new AnyDriverYouWant();
if (driver instanceof JavascriptExecutor) {
} else {
    throw new IllegalStateException("This driver does not support JavaScript!");

In your case, the Javascript will look something like this. Example as found here:


EDIT: Something worth looking into: if you're using C#, you can use FiddlerCore to intercept a request: http://chowson.github.io/block-requests-with-fiddlercore/

Basically, you'll use the BeforeRequest event handler to see if this request is for the particular script. If so, then you fake the response.

  • I used JavascriptExecutor but the DOM modification seems to be applied after the script execution. I can see that my script tag is empty but the auto download popup still showed off. For the moment it's not blocking, it's a 'dev' page so I removed the auto download from the source page. But I'm curious to know if it's possible with JS though
    – buzz2buzz
    Commented Jul 1, 2016 at 7:45
  • @buzz2buzz See my edit - FiddlerCore might offer a solution.
    – FDM
    Commented Jul 1, 2016 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.