0

I'm using the Selenium ChromeDriver with C#. I want to disable javascript to increase the testing speed. I have found a way to disable loading images, but I can't find how to disable javascript.

Update: I can disable js with the Firefox Driver using C#. The Question is how to disable javascript using the C# ChromeDriver specifically.

3
  • Does this answer your question? How to disable Javascript when using Selenium? Commented Oct 13, 2020 at 10:17
  • That link is about Firefox setting. I want to set the chromedriver with C#. Commented Oct 13, 2020 at 10:19
  • I don't know why people are downvoting this question. It's a valid question and the documentation isn't clear how to do this. Commented Oct 13, 2020 at 10:26

1 Answer 1

1

You need to set Experimental Options this is how you do it in C#.

var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

var chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("profile.managed_default_content_settings.javascript", 2);

var driver = new ChromeDriver(outPutDirectory, chromeOptions.ToCapabilities());
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for reply. I tested with this code. But I got an error. "invalid argument: entry 0 of 'firstMatch' is invalid from invalid argument:cannot parse capability:goog:chromeoptions"
It might need chromeOptions.ToCapabilities() changed last line answer.
When create new ChromeDriver, constructor of chromedriver has no option about DesiredCapabilites.
I fixed errors based on your code. Thank you very much.
Thanks if you could accept my answer that would be great.

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.