C# 如何使selenium打开https页面,该页面在自动运行时手动显示而不显示?

C# 如何使selenium打开https页面,该页面在自动运行时手动显示而不显示?,c#,selenium,google-chrome,automation,C#,Selenium,Google Chrome,Automation,可以使用chrome手动浏览htpps连接的网站并显示该网站。 通过selenium自动测试浏览同一站点,不显示页面,显示空页面。 如果我加载chrome用户配置文件,自动打开所需页面。 其他https站点(QA)不通过自动连接显示,问题在于生产站点。 是否可以向selenium添加任何设置以打开页面?如果有效,请尝试此操作 try this if works HashMap<String, Object> chromePrefs =

可以使用chrome手动浏览htpps连接的网站并显示该网站。 通过selenium自动测试浏览同一站点,不显示页面,显示空页面。 如果我加载chrome用户配置文件,自动打开所需页面。 其他https站点(QA)不通过自动连接显示,问题在于生产站点。 是否可以向selenium添加任何设置以打开页面?

如果有效,请尝试此操作
 try this if works           
            HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("profile.default_content_settings.popups", 0);
            chromePrefs.put("download.default_directory", downloadFilepath);            
            ChromeOptions options = new ChromeOptions();
            options.setExperimentalOption("prefs", chromePrefs);
            options.addArguments("--start-maximized");
            options.setExperimentalOption("useAutomationExtension", false);
            options.addArguments("disable-infobars");
            DesiredCapabilities cap = DesiredCapabilities.chrome();         
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, 
            UnexpectedAlertBehaviour.ACCEPT);
            cap.setCapability(ChromeOptions.CAPABILITY, options);
            driver.set(new ChromeDriver(cap));          
HashMap chromePrefs=新HashMap(); chromePrefs.put(“profile.default\u content\u settings.popups”,0); chromePrefs.put(“download.default\u目录”,downloadFilepath); ChromeOptions选项=新的ChromeOptions(); 选项。设置实验选项(“prefs”,chromePrefs); options.addArguments(“--start maximized”); options.setExperimentalOption(“useAutomationExtension”,false); options.addArguments(“禁用信息栏”); DesiredCapabilities=DesiredCapabilities.chrome(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true); cap.setCapability(CapabilityType.UNEXPECTED\u ALERT\u行为, 意外的行为(接受); 上限设置能力(色度选项、能力、选项); 驱动器组(新的色度驱动器(cap));
问题解决后,在此处发布解决方案。 网站未显示,因为公司WAF(防火墙)阻止了自动化请求。 自动化方面的解决方案是将代理添加到chrome配置文件选项中,而waf方面的规则是为允许访问应用程序的代理添加的

这是如何将代理添加到ChromeOptions类的示例:

ChromeOptions options = new ChromeOptions();
options.AddArgument("--user-agent=automation-client");

您可以发布初始化web驱动程序的代码和尝试与页面交互的代码吗?感谢您的帮助,问题已经解决。请参阅下面的答案。感谢您的帮助,问题已经解决。见下面的答案。