
- Selenium 教程
- Selenium - 首頁
- Selenium - 概述
- Selenium - 元件
- Selenium - 自動化測試
- Selenium - 環境設定
- Selenium - 遠端控制
- Selenium IDE 教程
- Selenium - IDE 簡介
- Selenium - 特性
- Selenium - 限制
- Selenium - 安裝
- Selenium - 建立測試
- Selenium - 建立指令碼
- Selenium - 控制流
- Selenium - 儲存變數
- Selenium - 警報和彈出視窗
- Selenium - Selenese 命令
- Selenium - 操作命令
- Selenium - 訪問器命令
- Selenium - 斷言命令
- Selenium - Assert/Verify 方法
- Selenium - 定位策略
- Selenium - 指令碼除錯
- Selenium - 驗證點
- Selenium - 模式匹配
- Selenium - JSON 資料檔案
- Selenium - 瀏覽器執行
- Selenium - 使用者擴充套件
- Selenium - 程式碼匯出
- Selenium - 程式碼輸出
- Selenium - JavaScript 函式
- Selenium - 外掛
- Selenium WebDriver 教程
- Selenium - 簡介
- Selenium WebDriver vs RC
- Selenium - 安裝
- Selenium - 第一個測試指令碼
- Selenium - 驅動程式會話
- Selenium - 瀏覽器選項
- Selenium - Chrome 選項
- Selenium - Edge 選項
- Selenium - Firefox 選項
- Selenium - Safari 選項
- Selenium - 雙擊
- Selenium - 右鍵單擊
- Python 中的 HTML 報告
- 處理編輯框
- Selenium - 單個元素
- Selenium - 多個元素
- Selenium Web 元素
- Selenium - 檔案上傳
- Selenium - 定位器策略
- Selenium - 相對定位器
- Selenium - 查詢器
- Selenium - 查詢所有連結
- Selenium - 使用者互動
- Selenium - WebElement 命令
- Selenium - 瀏覽器互動
- Selenium - 瀏覽器命令
- Selenium - 瀏覽器導航
- Selenium - 警報和彈出視窗
- Selenium - 處理表單
- Selenium - 視窗和選項卡
- Selenium - 處理連結
- Selenium - 輸入框
- Selenium - 單選按鈕
- Selenium - 複選框
- Selenium - 下拉框
- Selenium - 處理 iframe
- Selenium - 處理 Cookie
- Selenium - 日期時間選擇器
- Selenium - 動態 Web 表格
- Selenium - Actions 類
- Selenium - Action 類
- Selenium - 鍵盤事件
- Selenium - 鍵向上/向下
- Selenium - 複製和貼上
- Selenium - 處理特殊鍵
- Selenium - 滑鼠事件
- Selenium - 拖放
- Selenium - 手寫筆事件
- Selenium - 滾動操作
- Selenium - 等待策略
- Selenium - 顯式/隱式等待
- Selenium - 支援功能
- Selenium - 多選
- Selenium - 等待支援
- Selenium - 選擇支援
- Selenium - 顏色支援
- Selenium - ThreadGuard
- Selenium - 錯誤和日誌記錄
- Selenium - 異常處理
- Selenium - 其他
- Selenium - 處理 Ajax 呼叫
- Selenium - JSON 資料檔案
- Selenium - CSV 資料檔案
- Selenium - Excel 資料檔案
- Selenium - 跨瀏覽器測試
- Selenium - 多瀏覽器測試
- Selenium - 多視窗測試
- Selenium - JavaScript 執行器
- Selenium - 無頭執行
- Selenium - 捕獲螢幕截圖
- Selenium - 捕獲影片
- Selenium - 頁面物件模型
- Selenium - 頁面工廠
- Selenium - 記錄和回放
- Selenium - 框架
- Selenium - 瀏覽上下文
- Selenium - DevTools
- Selenium Grid 教程
- Selenium - 概述
- Selenium - 架構
- Selenium - 元件
- Selenium - 配置
- Selenium - 建立測試指令碼
- Selenium - 測試執行
- Selenium - 端點
- Selenium - 自定義節點
- Selenium 報告工具
- Selenium - 報告工具
- Selenium - TestNG
- Selenium - JUnit
- Selenium - Allure
- Selenium & 其他技術
- Selenium - Java 教程
- Selenium - Python 教程
- Selenium - C# 教程
- Selenium - Javascript 教程
- Selenium - Kotlin 教程
- Selenium - Ruby 教程
- Selenium - Maven 和 Jenkins
- Selenium - 資料庫測試
- Selenium - LogExpert 日誌記錄
- Selenium - Log4j 日誌記錄
- Selenium - Robot Framework
- Selenium - AutoIT
- Selenium - Flash 測試
- Selenium - Apache Ant
- Selenium - Github 教程
- Selenium - SoapUI
- Selenium - Cucumber
- Selenium - IntelliJ
- Selenium - XPath
- Selenium 其他概念
- Selenium - IE 驅動程式
- Selenium - 自動化框架
- Selenium - 關鍵字驅動框架
- Selenium - 資料驅動框架
- Selenium - 混合驅動框架
- Selenium - SSL 證書錯誤
- Selenium - 替代方案
- Selenium 有用資源
- Selenium - 問答
- Selenium - 快速指南
- Selenium - 有用資源
- Selenium - 自動化實踐
- Selenium - 討論
Selenium WebDriver - Safari 選項
Selenium Webdriver 可用於在 Safari 瀏覽器上執行自動化測試。某些功能和特性僅適用於 Apple 使用者的 Safari。Safari 是一款流行的瀏覽器,由 Apple 裝置預設提供。對於 Safari 瀏覽器版本 10 及更高版本,safaridriver 會自動安裝,無需單獨安裝。
safari 驅動程式預設安裝在作業系統上,而 Firefox 和 Chromium 瀏覽器則不是這樣。我們需要進行一些初始設定,在 Safari 瀏覽器中啟用“開發”選單,然後才能在其上實際執行測試。預設情況下,“開發”選單不可見。

為此,我們需要開啟 Safari,然後單擊“設定”。接下來,我們需要轉到“高階”選項卡,並選中“顯示 Web 開發人員功能”選項。

要開始在 Safari 瀏覽器上執行自動化測試,我們需要從終端執行命令:
safaridriver --enable
示例
讓我們以以下頁面為例,我們在此啟動一個 Safari 驅動程式會話以及 SafariOptions。然後,我們將獲取瀏覽器標題“Selenium Practice - Student Registration Form”和當前 URL Selenium Automation Practice Form。

要在 SafariDriver 以及 SafariOptions 類一起使用,我們需要新增匯入語句:
import org.openqa.selenium.safari.SafariOptions import org.openqa.selenium.safari.SafariDriver
程式碼實現
package org.example; import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.safari.SafariOptions; import java.util.concurrent.TimeUnit; public class SafariOpts { public static void main(String[] args) throws InterruptedException { // Using the Safari options SafariOptions opts = new SafariOptions(); WebDriver driver = new SafariDriver(opts); // adding an implicit wait of 15 secs driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // opening the Safari browser and launch a URL driver.get("https://tutorialspoint.tw/selenium/practice/selenium_automation_practice.php"); // get the page title System.out.println("Browser title is: " + driver.getTitle()); // get the current URL System.out.println("Current URL is: " + driver.getCurrentUrl()); // closing the browser driver.quit(); } }
輸出
Browser title is: Selenium Practice - Student Registration Form Current URL is: https://tutorialspoint.tw/selenium/practice/selenium_automation_practice.php Process finished with exit code 0
在上面的示例中,我們使用 SafariOptions 啟動了 Safari 瀏覽器,然後分別獲取了瀏覽器標題和當前 URL,並在控制檯中顯示訊息 - “瀏覽器標題為:Selenium Practice - Student Registration Form 和當前 URL 為:” Selenium Automation Practice Form。
Safari 瀏覽器始終將日誌(如果已啟用)儲存在以下位置 - ~/Library/Logs/com.apple.WebDriver/。與 Chrome、Firefox 等其他瀏覽器不同,我們無法選擇將日誌及其級別分別儲存到其他位置和值。
示例 - 捕獲 Safari 日誌
讓我們以一個啟用 Safari 日誌的示例為例。
package org.example; import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.safari.SafariDriverService; import org.openqa.selenium.safari.SafariOptions; import java.util.concurrent.TimeUnit; public class SafariOptsLogs { public static void main(String[] args) throws InterruptedException { // Using the Safari options SafariOptions opts = new SafariOptions(); WebDriver driver = new SafariDriver(opts); // adding an implicit wait of 15 secs driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // opening the Safari browser and launch a URL driver.get("https://tutorialspoint.tw/selenium/practice/selenium_automation_practice.php"); // enabling the Safari logs SafariDriverService service = new SafariDriverService.Builder().withLogging(true).build(); // get the page title System.out.println("Logging enabled: " + service); // close the browser driver.quit(); } }
輸出
Logging enabled: org.openqa.selenium.safari.SafariDriverService@3eeb318f
示例 - 停用 Safari 日誌
讓我們以一個停用 Safari 日誌的示例為例。
package org.example; import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; import org.openqa.selenium.safari.SafariDriverService; import org.openqa.selenium.safari.SafariOptions; import java.util.concurrent.TimeUnit; public class SafariOptsLogsFalse { public static void main(String[] args) throws InterruptedException { // Using the Safari options SafariOptions opts = new SafariOptions(); WebDriver driver = new SafariDriver(opts); // adding an implicit wait of 15 secs driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); // opening the Safari browser and launch a URL driver.get("https://tutorialspoint.tw/selenium/practice/selenium_automation_practice.php"); // disabling the Safari Logs SafariDriverService service = new SafariDriverService.Builder() .withLogging(false) .build(); // get the page title System.out.println("Launched Browser title is: " + driver.getTitle()); // get the current URL System.out.println("Current URL is: " + driver.getCurrentUrl()); // close the browser driver.quit(); } }
輸出
Browser title is: Selenium Practice - Tool Tips Current URL is: https://tutorialspoint.tw/selenium/practice/tool-tips.php
結論
本教程全面介紹了 Selenium WebDriver Safari 選項,到此結束。我們從描述 SafariOptions 類開始,並逐步講解了如何將 SafariOptions 與 Selenium Webdriver 一起使用的示例。這使您深入瞭解了 Selenium Webdriver 中的 SafariOptions 類。明智的做法是不斷練習您學到的知識,並探索與 Selenium 相關的其他內容,以加深您的理解並拓寬您的視野。