0

https://code.google.com/p/selenium/issues/detail?id=3175 Doesn't work.

So then I tried this,

ChromeOptions opts = new ChromeOptions();
opts.addArguments("--disable-javascript");
driver = new ChromeDriver(opts);

But then driver.get(website); javascript is enabled again. When it was on data; it was disabled.

Also I tried,

DesiredCaptabilities caps = DesiredCaptabilties.chrome();
caps.setJAvaScriptEnabled(fale);
driver = new ChromeDriver(caps); 
driver.get(Website); 

Nothing is working. Any advice?

Ya Wang
  • 1,758
  • 1
  • 19
  • 41

2 Answers2

3

javascriptEnabled just works on HTMLUnitDriver.

And ChromeDriver should have JavaScript enabled to work properly in the first place, so you can´t disable JavaScript if you use ChromeDriver2.

Wanping Qu
  • 54
  • 3
  • I managed to disable Javascript for `ChromeDriver 2.41.578706` like this: https://stackoverflow.com/a/57316009/1545579 – Mahdi Aug 01 '19 at 19:48
-1
static public void DisableJS () {
        driver.get("chrome://settings");
        driver.switchTo().frame("settings");
        driver.findElement(By.id("advanced-settings-expander")).click();
    driver.findElement(By.id("privacyContentSettingsButton")).click();
        //here do not allow js
        driver.findElement(By.xpath("//*[@id='content-settings-page']/div[2]/section[3]/div/div[2]/label/input")).click();
        driver.findElement(By.id("content-settings-overlay-confirm")).click();
    }
  • Hi and welcome! FYI: some explanations would significantly improve the quality of your answer. – mrun May 17 '17 at 14:43