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.

DalSoft
  • 10,673
  • 3
  • 42
  • 55
FastDev
  • 67
  • 7
  • Does this answer your question? [How to disable Javascript when using Selenium?](https://stackoverflow.com/questions/1285917/how-to-disable-javascript-when-using-selenium) – Liam Oct 13 '20 at 10:17
  • That link is about Firefox setting. I want to set the chromedriver with C#. – FastDev Oct 13 '20 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. – DalSoft Oct 13 '20 at 10:26

1 Answers1

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());
DalSoft
  • 10,673
  • 3
  • 42
  • 55