我们如何使用Selenium/TestNg禁用Chrome浏览器的网络安全 [英] How can we disable web security of chrome browser using selenium/TestNg
本文介绍了我们如何使用Selenium/TestNg禁用Chrome浏览器的网络安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在代码中使用selenium/testng
来使用以下命令,因为每次执行代码时,webdriver
都会创建一个新的浏览器实例,默认情况下会启用安全性.
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
推荐答案
尝试以下操作,更改路径并以符合您要求的斜杠:-
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/");
下面是列出所有可用的chrome标志的链接:-
Below is the link where all available chrome flags are listed :-
http://peter.sh/experiments/chromium-command-line-switches/
希望它会对您有所帮助:)
Hope it will help you :)
这篇关于我们如何使用Selenium/TestNg禁用Chrome浏览器的网络安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文