【问题标题】:Is is possible to disable certain javascript script in selenium?是否可以在 selenium 中禁用某些 javascript 脚本?
【发布时间】:2020-02-27 19:12:55
【问题描述】:

是否有可能以某种方式禁用 google chrome selenium 中的 javascript 脚本?脚本在我登录后启动并收集有关执行操作的数据。它也似乎在网络选项卡(开发人员控制台)中作为 GET 请求。

【问题讨论】:

    标签: javascript python selenium-webdriver


    【解决方案1】:

    此代码将禁用 selenium chrome 中的所有 javascript:

    @Test() public void Chrome_javascript_disable() throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\AnkitP\\Desktop\\Selenium\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        Map < String, Object > prefs = new HashMap < String, Object > ();
        prefs.put("profile.managed_default_content_settings.javascript", 2);
        options.setExperimentalOption("prefs", prefs);
        WebDriver driver = new ChromeDriver(options);
        driver.get("https://www.google.com/imghp");
        driver.findElement(By.name("q")).sendKeys("flowers");
        driver.findElement(By.className("Tg7LZd")).click();
        Thread.sleep(5000);
        driver.quit();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 2017-10-22
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多