如何在Selenium Web Driver中使用SSL证书?

我在Windows 7上使用Selenium Web Driver.

我正在尝试测试使用身份验证的网站,我需要使用SSL证书.

当我从Selenium中使用Firefox时,一切正常,但我注意到Selenium打开的Firefox浏览器会话没有注册任何证书,所以很明显它不起作用.

当我使用Selenium的Firefox“out”时,你就是高级首选项

当我使用Selenium打开的Firefox会话时,你就会一样

我试图保持会话打开并手​​动注册证书,但浏览器会话不会注册证书.

如果可能有用,那么你就是我的代码

package myTestProjects;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class GAMOPERA_Test_01 {

private static WebDriver driver = null;

public static void main(String[] args)  throws InterruptedException {

    // Create a new instance of the Firefox driver
    System.out.println("Creo una nuova sessione del browser Firefox ...");
    driver = new FirefoxDriver();

    //Put a Implicit wait, this means that any search for elements on the page Could take the time the implicit wait is set for before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // It is always advisable to Maximize the window before performing DragNDrop action
    System.out.println("Massimizzo la finestra del browser ...");
    driver.manage().window().maximize();
    Thread.sleep(3000L);

    //Launch the Sistema Piemonte Home Page
    System.out.println("Mi collego a Sistema Piemonte ...");
    driver.get("http://<my_site_url>");
    Thread.sleep(3000L);          

    // Find the element Accedi o 
    System.out.println("Accesso tramite certificato digitale ...");
    driver.findElement(By.xpath("/html/body/div[6]/div/div/div[2]/form/table/tbody/tr[3]/td/input")).click();        

    //driver.findElement(By.className("loginbutton")).click();
    Thread.sleep(3000L); 

    // Print TEST = OK!!
    System.out.println("TEST = OK !!");
    //driver.quit();

        }
}

有什么建议?

解决方法:

我已经解决了!

在网上冲浪我发现这篇文章http://seleniummonk.blogspot.it/p/how-to-handle-ssl-cerificates.html给了我解决方案.

我需要使用“Firefox配置文件”(我使用认的…),所以我可以拥有我需要的所有证书.

在这里,你是新的代码

package myTestProjects;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class GAMOPERA_Test_01 {

private static WebDriver driver = null;

public static void main(String[] args)  throws InterruptedException {

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile ffProfile = profile.getProfile("default"); 

    // Create a new instance of the Firefox driver
    System.out.println("Creo una nuova sessione del browser Firefox ...");
    driver = new FirefoxDriver(ffProfile);          

    //Put a Implicit wait, this means that any search for elements on the page Could take the time the implicit wait is set for before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // It is always advisable to Maximize the window before performing DragNDrop action
    System.out.println("Massimizzo la finestra del browser ...");
    driver.manage().window().maximize();
    Thread.sleep(3000L);

    //Launch the Sistema Piemonte Home Page
    System.out.println("Mi collego a Sistema Piemonte ...");
    driver.get("<my_site_url>");
    Thread.sleep(3000L);          

    // Find the element Accedi o 
    System.out.println("Accesso tramite certificato digitale ...");
    driver.findElement(By.xpath("/html/body/div[6]/div/div/div[2]/form/table/tbody/tr[3]/td/input")).click();        

    //driver.findElement(By.className("loginbutton")).click();
    Thread.sleep(3000L); 

    // Print TEST = OK!!
    System.out.println("TEST = OK !!");
    //driver.quit();

        }

}

我希望这可能有用!

相关文章

转载地址:https://www.cnblogs.com/mini-monkey/p/12104821...
web自动化测试过程中页面截图相对比较简单,可以直接使用sel...
目录前言一、Selenium简介二、浏览器驱动1.浏览器驱动参考2....
一、iframe的含义:iframe是HTML中框架的一种形式,在对界面...
转载请注明出处❤️作者:测试蔡坨坨原文链接:caituotuo.to...
'''##**认识selenium**​**下载:pipinstall...