<分区>
我想在代码中使用 selenium/testng
使用以下命令,因为每次执行代码时,webdriver
都会创建一个新的浏览器实例默认启用哪个安全性。
chrome.exe --disable-web-security
<分区>
我想在代码中使用 selenium/testng
使用以下命令,因为每次执行代码时,webdriver
都会创建一个新的浏览器实例默认启用哪个安全性。
chrome.exe --disable-web-security
最佳答案
试试这个,根据您的规范更改路径和斜杠:-
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 标志的链接:-
http://peter.sh/experiments/chromium-command-line-switches/
希望对你有帮助:)
关于java - 我们如何使用 selenium/TestNg 禁用 chrome 浏览器的网络安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33013378/