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

杀马特。学长 韩版系。学妹 提交于 2019-12-18 13:25:52

问题


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

回答1:


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 :)



来源:https://stackoverflow.com/questions/33013378/how-can-we-disable-web-security-of-chrome-browser-using-selenium-testng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!