Selenium WebDriver 如何處理 Edge 瀏覽器中的 SSL 證書?


我們可以使用 Selenium webdriver 處理 Edge 瀏覽器中的 SSL 證書。此操作藉助 EdgeOptions 類完成。我們將建立一個該類的物件,並將引數 setAcceptInsecureCerts 設定為 true 值。

最後,必須將此資訊傳遞給 webdriver 物件,以獲取所需的瀏覽器設定。SSL 是一種旨在在伺服器和瀏覽器之間建立安全連線的協議。

語法

EdgeOptions e = new EdgeOptions();
e.setAcceptInsecureCerts(true);

程式碼實現

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class EdgeBrwserSSL{
   public static void main(String[] args) {
      System.setProperty("webdriver.edge.driver",
      "C:\Users\ghs6kor\Desktop\Java\msedgedriver.exe");
      //instance of EdgeOptions
      EdgeOptions e = new EdgeOptions();
      //configure setAcceptInsecureCerts to true boolean value
      e.setAcceptInsecureCerts(true);
      //object of EdgeDriver
      WebDriver driver = new EdgeDriver(e);
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("application url");
   }
}

更新於: 2021 年 6 月 25 日

919 次瀏覽

開啟您的 職業生涯

完成課程並獲得認證

入門
廣告
© . All rights reserved.