2

I am using below code to disable java script in C# Selenium webdriver with specflow.

FirefoxProfile p = new FirefoxProfile();
p.SetPreference("javascript.enabled", false);
driver = new FirefoxDriver(p);

I am not able disable javascript for firefox browser. Can you please help me where I am wrong.

Thanks, Saurabh

1 Answer 1

1

There were multiple suggestions to use FirefoxProfile or DesireCapabilities to accomplish that. Those also never work for me. What did is the answer from a brilliant SO user @alecxe. See this

Luckily, there are people who do some great work for us so we can take the benefit. Use this add-on and that will solve your problem. And configuring that is real simple. Just right click on the Add to Firefox button and Save link as that will give you the option to save the .xpi. Then, configure the the Firefox profiler as follows.

FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(@"D:\Users\Saifur\Desktop\noScript.xpi");
IWebDriver driver = new FirefoxDriver(profile);

driver.Navigate().GoToUrl("https://stackoverflow.com/");

And, just to show you it's working I did a Scrrencast

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Saifur. It worked for me.. Can you please help to perform same for google Chrome?
@user3207067 Will take a look after work. Not on top of my head right now

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.