本文介绍了有没有办法使用RemoteWebDriver for SauceLabs禁用CORS检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题说明了一切,我试图在SauceLabs上执行一些硒测试,该测试加载了发出跨域请求的网页.我当时在想是否有办法以与平台无关的方式通过代码来禁用CORS.
解决方案
同时使用 ChromeDriver / Chrome 组合禁用
在参考文献
Outro
您可以在以下位置找到一些相关的讨论:
- 未捕获的DOMException:阻止了在页面中列出iframe时,通过访问跨域框架而访问源为"http://localhost:8080"的框架
- 错误:由于使用Selenium的相同/跨源策略,拒绝访问属性"x"的权限?
Question says it all, I m trying to execute some selenium tests on SauceLabs, the test loads a webpage that makes a cross domain request. I was thinking is there a way to disable CORS, in platform-independent way through code.
解决方案
While using ChromeDriver / Chrome combo to disable cors check you can use the --disable-web-security
argument.
which is defined in content_switches.cc as:
// Don't enforce the same-origin policy. (Used by people testing their sites.)
const char kDisableWebSecurity[] = "disable-web-security";
Code samples:
Windows:
ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); // don't enforce the same-origin policy options.addArguments("--disable-gpu"); // applicable to windows os only options.addArguments("--user-data-dir=~/chromeTemp"); // applicable to windows os only WebDriver driver = new ChromeDriver(options); driver.get("https://google.com");
OSX:
ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); // don't enforce the same-origin policy options.addArguments("--user-data-dir=/tmp/chrome_dev_test"); WebDriver driver = new ChromeDriver(options); driver.get("https://google.com");
Linux
ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-web-security"); // don't enforce the same-origin policy WebDriver driver = new ChromeDriver(options); driver.get("https://google.com");
References
- Disable same origin policy in Chrome
- Disable-web-security in Chrome 48+
- Run Chrome browser without CORS
Outro
You can find a couple of relevant discussions in:
- Uncaught DOMException: Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame while listing the iframes in page
- Error: Permission denied to access property "x" due to same/cross origin policy using Selenium?
这篇关于有没有办法使用RemoteWebDriver for SauceLabs禁用CORS检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!