<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之旅 廣告
                # 如何在 Selenium Webdriver 中使用 AutoIT:文件上傳示例 > 原文: [https://www.guru99.com/use-autoit-selenium.html](https://www.guru99.com/use-autoit-selenium.html) ## 什么是 AutoIt? **AutoIt** 是一種免費軟件的腳本語言,旨在自動執行 Windows GUI 和常規腳本。 它結合了鼠標移動,擊鍵和窗口控制操作來自動執行硒 Webdriver 無法完成的任務。 在本教程中,您將學習- * [為什么使用 AutoIt?](#5) * [如何下載和安裝 AutoIT](#1) * [通過元素標識符查找元素,并在 AutoIT 編輯器上編寫腳本。](#2) * [Selenium Webdriver](#3) 中的 AutoIT Upload 文件 ### 為什么使用 AutoIt? Selenium 是一個開放源代碼工具,旨在在不同的瀏覽器上自動化基于 Web 的應用程序,但可以處理應用程序中的窗口 GUI 和非 HTML 彈出窗口。 Selenium 不處理基于窗口的活動,因此需要 AutoIT。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/ad/60/ad603d1e4b08881d36e4e9f588bd9549_735x285.png "How to use AutoIT with Selenium") 繼續前進,我們將學習如何使用 autoIT 在 selenium Web 驅動程序中上傳文件。 為此,我們需要三個工具。 * Selenium Webdriver * AutoIT 編輯器和元素標識符 * 您要自動執行的窗口 ## 如何下載和安裝 AutoIT **步驟 1)**:轉到此[鏈接。](https://www.autoitscript.com/site/autoit/downloads/) **步驟 2)**:將鼠標懸停在“自動”和“自動編輯器”下拉菜單上。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/ea/a2/eaa2b40cdaaa0983f35e263444d2b0b0_915x392.png "How to use AutoIT with Selenium") **步驟 3)**單擊“ AutoIT”下載選項。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/9f/d6/9fd69a7a794f1920b6d4d3d2c96c6ade_445x336.png "How to use AutoIT with Selenium") **步驟 4)**:通過單擊“下載 Autoit”按鈕下載“ Autoit”。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/33/91/33912a611e2b6e533337a5b9b972ce49_811x523.png "How to use AutoIT with Selenium") **步驟 5)**:現在,通過單擊“下載”按鈕下載“自動編輯器”。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/73/79/7379f67c6d55f81b56ceb53fe610c47c_426x278.png "How to use AutoIT with Selenium") **步驟 6):**單擊鏈接,如下所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/4c/9b/4c9b1389636b5f3b66e947147766b6d8_973x464.png "How to use AutoIT with Selenium") 下載后,您將獲得兩個安裝文件,如下屏幕所示,第一個是 **AutoIt 版本 3** 設置,第二個是 **Scitautoit3** 。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/e5/e6/e5e6843c530537b88fce12a3032578ed_424x176.png "How to use AutoIT with Selenium") **步驟 6)**:用于安裝 AutoIT-單擊兩個 AutoIT 設置一個一個。 **步驟 7)**:成功安裝后-打開 AutoIT 編輯器。 轉到'C:\ Program Files(x86)\ AutoIt3 \ SciTE' ![How to use AutoIT with Selenium](https://img.kancloud.cn/57/19/57191f927e9ef0f0e8cd792de66829e4_399x178.png "How to use AutoIT with Selenium") 然后單擊“ SciTE.exe”文件,將打開 AutoIT 編輯器,如下面的屏幕所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/f0/0b/f00b138e75ccd1f32eb5e065ee5ca5f5_1362x269.png "How to use AutoIT with Selenium") **步驟 8)**:現在打開元素標識符。 轉到'C:\ Program Files(x86)\ AutoIt3' ![How to use AutoIT with Selenium](https://img.kancloud.cn/31/f9/31f9b22dacbc9e8a9d0af66f95e9c75c_391x134.png "How to use AutoIT with Selenium") 然后點擊“ Au3Info.exe”文件,元素標識符打開,如下圖所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/dc/15/dc15fecb20283e91f9b5f0b472d4e04e_322x482.png "How to use AutoIT with Selenium") **注意:**使用此元素標識符后,您需要手動關閉,它不會自動關閉。 ## 通過元素標識符查找元素,并在 AutoIT 編輯器上編寫腳本。 在此之下,我們將看到如何通過 AutoIT 元素標識符在文件上傳器窗口上查找元素(元素標識符是 Selenium IDE 之類的工具,標識符可以找到窗口 GUI 或非 HTML 彈出窗口的元素,并提供元素的屬性,例如 **title** ,**類**,**實例**)以及如何使用 3 種方法在 AutoIT 編輯器上編寫腳本。 **例如:**我們將使用 guru99 的“寫給我們”頁面上載簡歷(文檔文件)。 在“寫給我們”頁面上單擊“選擇文件”按鈕后,我們需要調用 AutoIT 腳本。 單擊下面的語句(選擇要上傳的部分)后,單擊“選擇文件”后,控件立即轉換為自動。 ``` Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe"); ``` 最后,當我們運行 Selenium 腳本時,它將填寫表格->上傳簡歷->提交表格。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/b6/62/b662745f8ebf2a3a0e2ed6c9b8f07ec5_950x761.png "How to use AutoIT with Selenium") **步驟 1)**:現在打開元素標識符-轉到“ C:\ Program Files(x86)\ AutoIt3”,然后單擊“ Au3Info.exe”文件,元素標識符窗口打開,如下圖所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/02/1e/021e9feb19e7f62b4ae7444db7525180_1004x732.png "How to use AutoIT with Selenium") **步驟 2)**:現在,通過單擊 Windows 活動中的“選擇文件”來打開文件上傳器窗口。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/e8/82/e88202a5ef16331f9b934e3e0a908e0c_358x283.png "How to use AutoIT with Selenium") **步驟 3)**:將查找工具拖到文件上傳器窗口的“文件名”框元素上,以找到基本屬性信息,如以下屏幕中的箭頭所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/30/06/300638540371bf45388c3a63e2d28f5d_826x412.png "How to use AutoIT with Selenium") 我們可以獲得屬性的值,即 **title ='Open'**, **class ='Edit'**和 **instance ='1'**,如下所示。 這些值用于編寫 AutoIT 腳本,如以下步驟 4 中所述。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/79/6c/796cbc4d6d1f2a4142b59b1abd855860_312x471.png "How to use AutoIT with Selenium") **步驟 4)**:現在打開 AutoIT 腳本編輯器,轉到'C:\ Program Files(x86)\ AutoIt3 \ SciTE',然后從 1 <sup>中單擊“ SciTE.exe”,如步驟 7 所示。 st</sup> 主題。 開始編寫用于選擇要上傳文件的腳本。 根據需要,可以在腳本中使用很多可用的方法,但是現在我們將重點介紹以下方法,因為編寫文件上傳腳本需要這些方法: 1. **ControlFocus** (“ title”,“ text”,controlID) **//將輸入焦點設置到窗口上的給定控件。** 2. **ControlSetText** (“標題”,“文本”,controlID,“需要上傳的文件路徑”) **//設置控件的文本。** 3. **ControlClick** (“ title”,“ text”,controlID) **//將鼠標單擊命令發送到給定控件。** 您可以看到如下面的屏幕所示顯示了許多方法。 AutoIT 的優點是,它類似于 Eclipse,可以為您建議一些方法。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/14/42/14424a42842a8a343093cd6f19388498_409x231.png "How to use AutoIT with Selenium") 在 AutoIT 編輯器中,我們選擇了**“控制焦點”** 方法。 元素標識符已經打開并最小化,因為在上面的步驟 3 中已經標識了元素。我們可以通過最大化它來打開它。 現在,我們將從“ ControlFocus”和“ ControlSetText”方法的元素標識符中獲取值,因為這些方法適用于同一元素,即“文件名”文本框,但對于“ ControlClick”方法,則需要捕獲不同元素的值,即“ Open” 按鈕。 **ControlFocus** 方法的參數值: 此方法將焦點設置到文件上傳器窗口的“文件名”文本框中。 * 第一個參數**標題**為“打開”。 * 我們忽略第二個參數,不需要**文本**。 * 第三個參數 **controlID** 是 class ='Edit'和 Instance ='1'的組合,即。 “編輯 1”。 ``` ControlFocus("Open","","Edit1") // This method sets input focus to 'File name' text box. ``` ![How to use AutoIT with Selenium](https://img.kancloud.cn/74/ca/74ca8783a5efc84cfd6e3c116b6224ab_806x424.png "How to use AutoIT with Selenium") **ControlSetText** 方法的參數值: 此方法用于定義我們需要在“文件名”文本框中上載的文件的路徑。 換句話說,可以說此方法用于將文本設置為輸入元素。 * 第一個參數**標題**為“打開”。 * 我們忽略第二個參數,不需要**文本**。 * 第三個參數 **controlID** 是 class ='Edit'和 Instance ='1'的組合,即“ Edit1”。 * 第四個參數**新文本**傳遞了我們需要上傳的文件的路徑。 ``` ControlSetText("Open","","Edit1","E:\Resume\resume.doc") // This method input file path of a control. ``` ![How to use AutoIT with Selenium](https://img.kancloud.cn/45/05/4505d61a2f6b3332df813d497bbe8a02_927x214.png "How to use AutoIT with Selenium") 完成上述步驟后,不要關閉窗口(編輯器和元素標識符),保持打開狀態。 再次需要打開文件上傳器窗口,以查找“打開”按鈕的屬性,如下面的第 5 步所示。 **步驟 5)**:現在將查找工具拖到文件上傳器窗口的“打開”按鈕元素上,以查找基本屬性信息。 以前的值(即“文件名”文本框的屬性)將被“打開”按鈕的新值覆蓋。 您可以看到在 AutoIT 元素標識符窗口中,類屬性現在已更改為“按鈕”,以前是“編輯”。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/99/47/9947a16b49dd22911ac0be7149720767_872x469.png "How to use AutoIT with Selenium") 我們可以獲取屬性的值,即 **title ='Open'**, **class ='Button'**和 **instance ='1'**,如下所示。 這些值用于編寫 Autoit 腳本,如下所述。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/9a/1c/9a1cb9979e27c0b06f6f1a45028f167e_312x471.png "How to use AutoIT with Selenium") **ControlClick** 方法的參數值: 此方法單擊文件上傳器窗口的“打開”按鈕。 * 第一個參數**標題**為“打開”。 * 我們忽略第二個參數; 不需要**文本**。 * 第三個參數 **controlID** 是類和實例的組合,即“ Button1”。 ``` ControlClick("Open","","Button1") //This method click on 'Open' button of file uploader. ``` ![How to use AutoIT with Selenium](https://img.kancloud.cn/0c/1e/0c1e5d63ca4bb25d329c9e0f1cc8d8db_926x215.png "How to use AutoIT with Selenium") **步驟 6)**:您可以在下面的屏幕中看到 AutoIT 腳本已完成以處理文件上傳器。現在您可以關閉元素標識符并將腳本保存為“ FileUpload”在給定位置(E:\ AutoIT )。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/fc/9b/fc9b3b273ab2bdfeb175cd05653b465c_776x625.png "How to use AutoIT with Selenium") 現在您無法直接執行此腳本,需要編譯此腳本。 要編譯此腳本,您有兩個選項“ **編譯腳本 x64** ”和“ **編譯腳本 x86** ”,如果您使用的是 Windows 32 位計算機,則可以使用“ **編譯” 腳本 x86“** ,對于 Windows 64 位計算機,則使用” **編譯腳本 x64** ”。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/cf/78/cf789cba6580b4a8956e510328023017_569x537.png "How to use AutoIT with Selenium") **步驟 7):編譯后生成的** **'FileUpload exe'**文件,您可以在以下屏幕中看到。 現在我們可以在 Selenium webdriver 腳本中使用此文件。 [![How to use AutoIT with Selenium](https://img.kancloud.cn/c8/47/c8473ad6790798dfb5daa56268573e71_702x193.png "How to use AutoIT with Selenium") ](/images/jsp/022916_1258_HowtouseAut24.png) 現在,我們將在 Selenium Web 驅動程序中使用此 AutoIT 腳本。 檢查下面的輸出。 ## Selenium Webdriver 中的 AutoIT Upload 文件 在 Selenium 腳本中,我們找到表單的元素,并根據需要在每個元素中填充數據,并通過執行從 AutoIT 腳本生成的 AutoIT exe 文件上載“ resume.doc”文件,然后允許使用 selenium 腳本提交表單。 * 打開 Eclipse 并開始編寫代碼。 * 當硒單擊“選擇文件”按鈕時,將打開文件上傳器框。 * 然后我們需要調用 AutoIT 腳本,將控件立即轉移到 AutoIT 以上傳文件,然后將控件發送回 selenium,如下所示。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/6c/11/6c110af8bf299cf2515983478bdf21e0_374x308.png "How to use AutoIT with Selenium") **步驟 1)**:開發日食中的硒腳本。 * **運行時**類允許腳本與腳本在其中運行的環境進行交互。 * **getRuntime()**獲取與此進程關聯的當前運行時。 * **exec()**方法執行 AutoIT 腳本(FileUpload.exe)。 ``` Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe"); ``` 上一行將在硒中調用 **AutoIT 腳本**并上傳文件。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/54/94/5494dec6409f2a66f8182e898d4a8c44_645x553.png "How to use AutoIT with Selenium") **步驟 2)**:在 Eclipse 中執行 Selenium 腳本。 ``` importjava.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class FileUpload { public static void main(String[] args) throws IOException { WebDriver driver=new FirefoxDriver(); driver.get("http://demo.guru99.com/test/autoit.html"); driver.findElement(By.id("postjob")).click(); driver.findElement(By.id("input_3")).sendKeys("Gaurav"); driver.findElement(By.id("id_4")).sendKeys("This email address is being protected from spambots. You need JavaScript enabled to view it. "); driver.findElement(By.id("input_4")).click(); // below line execute the AutoIT script . Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe"); driver.findElement(By.id("input_6")).sendKeys("AutoIT in Selenium"); driver.findElement(By.id("input_2")).click(); driver.close(); } } ``` **步驟 3)**:驗證輸出,成功上傳 resume.doc 文件,并顯示感謝信息。 ![How to use AutoIT with Selenium](https://img.kancloud.cn/88/39/8839582ca4fa56bc6762421a503b13f1_965x514.png "How to use AutoIT with Selenium") **結論:** * 下載并安裝了 Element Identifier 和 AutoIT 編輯器。 * 打開要執行操作的站點。 * 元素標識符標識文件上載器窗口的元素。 * 在編輯器中借助元素標識符準備了 AutoIT 腳本。 * Selenium Webdriver 腳本中使用了 Autoit 腳本。 * 執行了硒腳本。 * 輸出:成功上傳文件。 ***本文由 Gaurav Nigam 發表***
                  <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>

                              哎呀哎呀视频在线观看