繁体   English   中英

ChromeDriver在Java中禁用Javascript

[英]ChromeDriver Disable Javascript in Java

https://code.google.com/p/selenium/issues/detail?id=3175不起作用。

那么我试过这个,

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才能正常工作,因此如果您使用ChromeDriver2,则无法禁用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();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM