How can we disable web security of chrome browser using selenium/TestNg

22,150

Try something this, Change the path and slashing accoding to your specifications :-

            WebDriver driver=null;
            System.setProperty("webdriver.chrome.driver","./src//lib//chromedriver");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            ChromeOptions options = new ChromeOptions();
            options.addArguments("test-type");
            options.addArgument("--start-maximized");
            options.addArguments("--disable-web-security");
            options.addArguments("--allow-running-insecure-content");
            capabilities.setCapability("chrome.binary","./src//lib//chromedriver");
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            driver = new ChromeDriver(capabilities);
            driver.get("https://www.google.com/");

Below is the link where all available chrome flags are listed :-

http://peter.sh/experiments/chromium-command-line-switches/

Hope it will help you :)

Share:
22,150
SHARAN
Author by

SHARAN

Software Engineer

Updated on July 09, 2022

Comments

  • SHARAN
    SHARAN almost 2 years

    I want to use the following command using selenium/testng inside my code since every-time I execute the code, a new instance of browser is created by webdriver in which security is enabled by default.

    chrome.exe --disable-web-security