How to disable JavaScript in browser using Selenium (Java)?

前端 未结 6 1908
抹茶落季
抹茶落季 2020-12-20 08:01

In my feature automation, I need to disable JavaScript in browser and run the flow. How to disable JavaScript?

Tried DesiredCapabilities for firefox and Chrome.

6条回答
  •  -上瘾入骨i
    2020-12-20 08:14

    I don't know Java, but maybe a solution for Python 3 will help you.

    in Python, you can use Options() instead of FirefoxProfile() to deactivate JavaScript:

    from selenium.webdriver.firefox.options import Options
    options = Options()
    options.preferences.update({"javascript.enabled": False})
    driver = webdriver.Firefox(options=options)
    driver.get('about:config')
    

    Maybe Java this:

    FirefoxOptions options = new FirefoxOptions();
    options.preferences.update({"javascript.enabled": False});
    WebDriver driver = new FirefoxDriver(options);
    driver.get('about:config')
    

提交回复
热议问题