Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ChromeDriver在Java中禁用Javascript_Java_Javascript_Selenium Chromedriver - Fatal编程技术网

ChromeDriver在Java中禁用Javascript

ChromeDriver在Java中禁用Javascript,java,javascript,selenium-chromedriver,Java,Javascript,Selenium Chromedriver,不起作用 然后我试了一下 ChromeOptions opts = new ChromeOptions(); opts.addArguments("--disable-javascript"); driver = new ChromeDriver(opts); 然后是driver.get(网站); javascript再次启用。当它在数据上时;它被禁用了 我也试过, DesiredCaptabilities caps = DesiredCaptabilties.chrome(); caps.s

不起作用

然后我试了一下

ChromeOptions opts = new ChromeOptions();
opts.addArguments("--disable-javascript");
driver = new ChromeDriver(opts);
然后是driver.get(网站); javascript再次启用。当它在数据上时;它被禁用了

我也试过,

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

什么都没用。有什么建议吗?

javascriptEnabled只适用于HTMLUnitDriver


ChromeDriver应该首先启用JavaScript才能正常工作,因此如果您使用ChromeDriver 2,就不能禁用JavaScript。

您好,欢迎!仅供参考:一些解释将显著提高您答案的质量。我成功禁用了ChromeDriver 2.41.578706的Javascript,如下所示:
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();
    }