Home » c# » c# – How to make selenium open https page, which displayed manually and not displayed while automated run?-Exceptionshub

c# – How to make selenium open https page, which displayed manually and not displayed while automated run?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

Browsing with chrome to web site with htpps connection manually is available and display the site.
Browsing same site by selenium automated test, doesn’t display the page, display empty page.
If i load chrome user profile, automation do open the required page.
Other https site (QA) does displayed through automated connection, the problem is with production sites.
Is there any setting can be added to selenium to open the page?

How to&Answers:
 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));          

Answer:

After the issue solved, posting here the solution.
The site wasn’t displayed because automation requests were blocked by company WAF (firewall).
The solution on the automation side was to add agent into chrome profile options and on the waf side rule was added for the agent that allows access to the application.

This is example of how the agent added into ChromeOptions class:

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