java 我们如何使用 selenium/TestNg 禁用 chrome 浏览器的网络安全

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33013378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:04:36  来源:igfitidea点击:

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

javagoogle-chromeseleniumselenium-webdriverselenium-chromedriver

提问by SHARAN

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

我想selenium/testng在我的代码中使用以下命令,因为每次执行代码时,都会创建一个新的浏览器实例,webdriver其中默认启用安全性。

chrome.exe --disable-web-security

回答by Shubham Jain

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

以下是列出所有可用 chrome 标志的链接:-

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

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

Hope it will help you :)

希望它会帮助你:)