<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 使用帶有示例的 Webdriver 的 Selenium 代理身份驗證 > 原文: [https://www.guru99.com/selenium-proxy-authentication.html](https://www.guru99.com/selenium-proxy-authentication.html) ## 什么是代理? 代理充當客戶端發送請求和服務器響應之間的中介。 代理的主要用途是維護多個交互式系統之間的隱私和封裝。 代理還可以充當客戶端和 Web 服務器之間的防火墻,從而在 Web 上增加另一層安全性。 當必須根據網站內容將客戶使用的網站標記為允許或阻止時,尤其可以使用此功能。 此過程稱為“內容過濾”,最常用于教育機構,公司辦公室等。借助代理可以輕松完成內容過濾。 就 Internet 而言,代理可以實現為單獨的服務器,位于客戶端計算機與實際的 Web 或數據庫服務器之間進行響應。 在本教程中,您將學習 * [什么是代理?](#1) * [SOCKS 和 HTTP 代理](#2)之間的區別 * [2 在 Chrome 中使用 Selenium 進行 HTTP 代理身份驗證的方法](#3) * [使用 AutoIT 工具](#4) * [使用警報](#5) ## SOCKS 和 HTTP 代理之間的區別 | 襪子 | HTTP 代理 | | SOCKS 代表固定插座。 通常用作客戶端和服務器之間的防火墻 | HTTP 代理也可以用作客戶端和服務器之間的防火墻,但只能用于 HTTP 請求 | | SOCKS 不解釋正在交換的數據 | HTTP 代理解釋客戶端和服務器之間正在交換的數據 | | 性能方面較慢 | 與襪子相比性能更好 | ## 2 在 Chrome 中使用 Selenium 進行 HTTP 代理身份驗證的方法 可以使用以下方法在 Chrome 中使用 Selenium 進行 HTTP 代理身份驗證 * 使用 AutoIT 工具 * 使用警報 ## 使用 AutoIT 工具 Auto IT 是用于 Windows 桌面自動化的第三方工具。 由于 Selenium 僅處理基于 Web 的彈出窗口和窗口,因此無法使用 Selenium 處理操作系統控件。 這要求使用外部第三方工具(例如 Auto IT)與 Selenium 集成。 因此,Auto IT 最常用于處理網站上的文件上傳和文件下載。 要使用 AutoIT,您需要在我們的本地計算機上下載并安裝 AutoIT 軟件。 [文章](https://www.guru99.com/use-autoit-selenium.html)中介紹了下載 AutoIT 的安裝。 打開程序– Autoit 工具– SciTE 腳本編輯器,然后在 Autoit 編輯器中添加以下提到的 AutoIt 腳本,并將其另存為系統中的“ ProxyAuthentication.au3” 編譯文件并將其轉換為“ ProxyAuthentication.exe”。 在 Eclipse 中,將 Auto IT 文件添加到 Selenium Script 中并運行 以下是用于 HTTP 代理身份驗證的 AutoIT 腳本 ``` Send("guru99{ENTER}") Send("guru99{ENTER}") ``` 您需要使用以下代碼傳遞自動 IT 文件以在 Selenium Webdriver 上執行 **源代碼:** ``` package Guru99Demo; import java.io.IOException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class AutoITDemo { public static void main(String[] args) throws IOException { System.setProperty("webdriver.chrome.driver", "D:\\ chromedriver.exe");; WebDriver driver = new ChromeDriver(); driver.get("http://demo.guru99.com/test/basic_auth.php"); //Passing the AutoIt Script to Selenium Runtime.getRuntime().exec("D:\\Data_Personal\\ProxyAuthentication.exe"); } } ``` **代碼說明:** * 第一步,您正在通過設置系統屬性以指向 chromedriver.exe 文件來初始化 Chrome 驅動程序的實例 * 在第二步中,您將初始化 Web 驅動程序的對象,并使用 get 方法傳遞網站 URL。 * 最后,您使用 AutoIT 腳本文件將用戶名和密碼傳遞給 HTTP 代理身份驗證彈出窗口 **代碼輸出:** <center> <figure>![](https://img.kancloud.cn/a0/7a/a07a3e58f2e24dbf75087ff8f164dd9d_737x288.png) <figcaption style="display: table;">Username Alert Handling Using AutoIT</figcaption> </figure> </center> <center> <figure>![](https://img.kancloud.cn/b8/ad/b8ad2df744a8838ee99540e965b96ea9_773x312.png) <figcaption style="display: table;">Password Alert Handling Using AutoIT</figcaption> </figure> </center> <center> <figure>![](https://img.kancloud.cn/d2/71/d271560584e2cacb9892197a8bfaec7c_821x334.png) <figcaption style="display: table;">Proxy Authentication Success Screen</figcaption> </figure> </center> ## 使用警報 警報是 Selenium Web 驅動程序提供的簡單的內置功能。 您可以使用 Selenium Web 驅動程序來處理代理身份驗證彈出窗口,方法是切換到 HTTP 代理身份驗證警報并將用戶名和密碼直接傳遞給警報。 借助發送密鑰方法。 **范例**: 測試場景: 使用 Selenium Web 驅動程序中的警報處理網站上的 HTTP 代理身份驗證彈出窗口: [http://demo.guru99.com/test/basic_auth.php](http://demo.guru99.com/test/basic_auth.php) 。 源代碼示例: ``` package Guru99Demo; import java.io.IOException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class AlertsDemo { public static void main(String args[]) throws IOException { System.setProperty("webdriver.chrome.driver", "D:\\Data_Personal\\Software\\chromedriver_win32\\chromedriver.exe");; WebDriver driver = new ChromeDriver(); driver.get("http://demo.guru99.com/test/basic_auth.php"); // Handling Username alert driver.switchTo().alert().sendKeys("guru99"); driver.switchTo().alert().accept(); // Handling Password alert driver.switchTo().alert().sendKeys("guru99"); driver.switchTo().alert().accept(); } } ``` **Code Output:** 代理身份驗證成功完成。 ### 代碼說明: * 最初,您通過設置 webdriver 屬性以指向 chromedriver.exe 文件的位置來實例化 Chrome 驅動程序的實例 * 然后,通過將 URL 作為參數傳遞給 driver.get()方法來打開所需網站的 URL。 * 打開 URL 后,您將切換到用戶名警報并發送用戶名– guru99。 然后,您使用 alert.accept 方法在警報上單擊“確定”按鈕。 * 然后,您將切換到密碼警報并發送密碼– guru99。 然后,您使用 alert.accept 方法在警報上單擊“確定”按鈕。 ### 摘要 * 代理充當客戶端發送請求和服務器響應之間的中介。 代理的基本用途是維護多個交互式系統之間的隱私和封裝。 * 可以使用以下方法在 Chrome 中使用 Selenium 進行 HTTP 代理身份驗證 * 在網站 URL 中傳遞用戶名和密碼 * 使用 AutoIT 工具 * 使用警報 * 在以上三種方法中,使用警報是在 Selenium Webdriver 中處理 HTTP 代理身份驗證的最有效方法
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看