Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用selenium/TestNg禁用chrome浏览器的web安全性_Java_Google Chrome_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Java 如何使用selenium/TestNg禁用chrome浏览器的web安全性

Java 如何使用selenium/TestNg禁用chrome浏览器的web安全性,java,google-chrome,selenium,selenium-webdriver,selenium-chromedriver,Java,Google Chrome,Selenium,Selenium Webdriver,Selenium Chromedriver,我想在我的代码中使用以下命令selenium/testng,因为每次执行代码时,都会由webdriver创建一个新的浏览器实例,其中默认启用了安全性 chrome.exe --disable-web-security 尝试以下操作,根据您的规范更改路径和斜线:- WebDriver driver=null; System.setProperty("webdriver.chrome.driver","./src//lib//chromedriver

我想在我的代码中使用以下命令
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标志的链接:-


希望它能帮助您:)

我仍然无法使用禁用web安全模式打开url。。是否可以使用selenium测试桌面应用程序?不,无法使用selenium测试桌面应用程序。我已更新了答案。您能再试一次吗?我刚刚在ChromrDriver Const中通过了选项,现在可以使用了。非常感谢。。驱动程序=新的色度驱动程序(可选);哎呀!!还有一件事要说。。不传递选项,而传递功能。。。功能本身包含选项参数。。。再次更新我的答案