Selenium Webdriver如何處理Firefox中的SSL證書?
我們可以透過使用FirefoxProfile類,利用Selenium webdriver來處理Firefox中的SSL證書。 然後將parametersetAcceptUntrustedCertificates引數設定為true。 SSL是一種用來在客戶端(瀏覽器)和伺服器之間建立安全連線的協議。
SSL會檢查網站的真實性,並在訪問者向該網站傳送或獲取資訊時對訪問者進行編碼。SSL證書的一些優點有:-
透過增加業務增長來贏得使用者的信任。
為線上支付提供一個安全閘道器,用於保護使用者名稱、密碼以及其他銀行資訊等客戶資料。
遠離駭客威脅。
樹立良好的品牌價值,例如谷歌會給擁有有效SSL的網站一個好的排名。
SSL證書網站以https://開頭,在那裡我們可以在位址列中找到一個綠色的鎖形圖示,如果連線是安全的。
語法
FirefoxProfile p=new FirefoxProfile(); p.setAcceptUntrustedCertificates(true);
示例
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; public class SSLErrorFirefox{ public static void main(String[] args) { //DesiredCapabilities object DesiredCapabilities c=DesiredCapabilities.internetExplorer(); //set FirefoxProfile FirefoxProfile p=new FirefoxProfile(); // configure setAcceptUntrustedCertificates to true p.setAcceptUntrustedCertificates(true); System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); //configure this profile to browser WebDriver driver=new FirefoxDriver(p); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("application url to be entered"); } }
廣告