Your connection is not secure - using Selenium.Web

2019-09-21 01:18发布

问题:

I'm writing tests with Selenium + C# and I face an important issue because I didn't found solution when I test my site with secure connection (HTTPS). All solutions I found on stackoverflow are out of date or doesn't work. I tried to exercise all solutions from below question: Selenium Why setting acceptuntrustedcertificates to true for firefox driver doesn't work?

But they did not help me solve the problem Nor is it the solution of using Nightly FireFox. Still, when the selenium loading Firfox browser, I see the page: "Your connection is not secure".

Configuration:

  • Firefox v56.0
  • Selenium.Firefox.WebDriver v0.19.0
  • Selenium.WebDriver v3.6.0

my code is:

                    FirefoxOptions options = new FirefoxOptions();
                    FirefoxProfile profile = new FirefoxProfile();
                    profile.AcceptUntrustedCertificates = true;
                    profile.AssumeUntrustedCertificateIssuer = false;
                    options.Profile = profile;
                    driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService() , options , TimeSpan.FromSeconds(5));
                    Drivers.Add(Browsers.Firefox.ToString() , driver);

Thank for your help!

Updates to my question here:

Note 1: To anyone who has marked my question as a duplicate of this question:

Firefox selenium webdriver gives “Insecure Connection” I thought that it is same issue, but I need solution for C#, I try match your JAVA code to my above code

First, I changed to TRUE the below statment:

     profile.AssumeUntrustedCertificateIssuer = true;

second, I create new FF profile ("AutomationTestsProfile") and try to use it:

Try 1:

       FirefoxProfile profile = new FirefoxProfileManager().GetProfile("AutomationTestsProfile");

try 2:

       FirefoxProfile profile = new FirefoxProfile("AutomationTestsProfile");

I Run 2 options, but still the issue exists.

Note 2: I attached screenshot of my problem, it appears when the driver try to enter text to user-name on login page.

I noticed that when I open my site with FF, Firefox displays a lock icon with red strike-through red strikethrough icon in the address bar,

but near the username textbox not appears the msg:

"This connection is not secure. Logins entered here could be compromised. Learn More" (as you writed on the duplicate question),

So maybe there is a different problem?

回答1:

You are setting the properties on the profile. The FirefoxOptions has a property AcceptInsecureCertificates, set that to true.

Forget the profile, this is what you want:

var op = new FirefoxOptions
{
    AcceptInsecureCertificates = true
};

Instance = new FirefoxDriver(op);


回答2:

It works for me for following settings (same as above):

My env:

win 7

firefox 61.0.2 (64-bit)

Selenium C# webdriver : 3.14.0

geckodriver-v0.21.0-win32.zip

==============================

FirefoxOptions options = new FirefoxOptions();

options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";

options.AcceptInsecureCertificates = true;

new FirefoxDriver(RelativePath,options);