<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 9Q WebDriver – 處理驗證碼 > 原文: [https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/](https://javabeginnerstutorial.com/selenium/9q-webdriver-handling-captcha/) 有人說驗證碼嗎? 好吧,我聽到了! 讓我們看看如何使用 Selenium WebDriver 處理這些問題,是的,我們將嘗試盡快完成這項工作,因為今天晚些時候我將不得不參加比賽。 *準備開始* **CAPTCHA** 是“`Completely Automated Public Turing test to tell Computers and Humans Apart`”(用于分辨電腦和人類的完備自動化公開圖靈測試)的首字母縮寫。 哦,別生我的氣! 那不是錯字! 確實有一個叫做`backronym`的**縮寫**。 當由其他詞的縮寫形成縮寫時,稱為縮寫。 但是,如果創建了一個新短語以適合已經存在的首字母縮寫,那么它被稱為簡稱。 因此,現在您知道什么是簡稱,并且 CAPTCHA 代表什么,讓我們詳細介紹一下。 驗證碼主要用于確定用戶是否為人類。 它會生成圖像或人類可以解決的某種形式的測試,但漫游器/計算機程序無法解決。 因此,其主要目的是防止漫游器和其他自動化程序從網站獲取任何敏感信息。 因此, **驗證碼可以殺死自動化!** 如果我們能夠使其自動化,那么使用驗證碼的原因就變得毫無價值。 我有袖子嗎? 讓我看看… 1. 出于測試目的,我們總是可以要求開發人員 1. **禁用**驗證碼驗證 2. 提供**解決方法**或后門以獲取驗證碼值 3. 調整驗證碼,使其每次都接受一個**特定輸入值** 4. 開發一種方法,將隨機文本存儲在驗證碼圖像的`alt`屬性中,然后可以使用可用的定位符獲取該隨機文本并將其傳遞到驗證碼文本框中 但是,請確保它們僅在測試環境中處于活動狀態,并且僅用于自動化目的。 請注意,在使用上述這些方法進行測試時,*應用安全性*受到損害。 2. 如果您想按原樣測試應用,即在不出于自動化目的對測試環境進行任何修改的情況下,請分離所有涉及驗證碼驗證的測試腳本并將其打包為單個測試套件。 在人為干預的情況下運行此測試套件。 **我知道這是部分自動化,但并非總是可以在給定的情況下將所有內容自動化。 為了得到一些東西,你應該準備放棄一些東西。** 1. 除驗證碼外,整個測試用例均可自動執行。 2. 可以使用隱式或顯式等待,并且提示用戶輸入顯示的驗證碼。 3. 運行測試腳本時,將照常執行每個步驟。 到達提示命令后,瀏覽器將彈出一個窗口。 用戶輸入屏幕上顯示的驗證碼。 4. 手動輸入驗證碼后,將繼續執行測試用例,并在瀏覽器上運行后續步驟。 這是我之前的一個項目中遵循的過程。 因為此方法可確保被測應用恰好是將被推入生產環境的應用,并且安全性絲毫不受影響。 讓我們看一個示例來更好地理解。 *場景* 1. 打開 Firefox 瀏覽器 2. 導航至 https://www.in.ckgs.us/myaccount/ 3. 通過`cssSelector`找到“當前護照號碼”文本框:標記和名稱屬性 4. 輸入“`123456789`” 5. 提示用戶進行干預并輸入顯示的驗證碼 6. 通過 ID 找到驗證碼文本框 7. 將用戶輸入的值發送到找到的驗證碼文本框中 8. 在 Eclipse IDE 中驗證 JUnit 窗格是否成功 此方案的 JUnit 代碼是, ```java package com.blog.junitTests; import java.util.concurrent.TimeUnit; import javax.swing.JOptionPane; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class CaptchaValidation { //Declaring variables private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception{ // Selenium version 3 beta releases require system property set up System.setProperty("webdriver.gecko.driver", "E:\\Softwares\\Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe"); // Create a new instance for the class FirefoxDriver // that implements WebDriver interface driver = new FirefoxDriver(); // Implicit wait for 5 seconds driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // Assign the URL to be invoked to a String variable baseUrl = "https://www.in.ckgs.us/myaccount/"; } @Test public void testPageTitle() throws Exception{ // Open baseUrl in Firefox browser window driver.get(baseUrl); // Locate 'Current Passport Number' text box by cssSelector: tag and name attribute WebElement passportNo = driver.findElement(By.cssSelector("input[name='currentPassportNo']")); // Clear the default placeholder or any value present passportNo.clear(); // Enter/type the value to the text box passportNo.sendKeys("123456789"); //prompting user to enter captcha String captchaVal = JOptionPane.showInputDialog("Please enter the captcha value:"); //Type the entered captcha to the text box driver.findElement(By.id("recaptcha_response_field")).sendKeys(captchaVal); } @After public void tearDown() throws Exception{ // Close the Firefox browser driver.close(); } } ``` *執行結果* 注釋清楚地提供給每一行代碼。 ```java String captchaVal = JOptionPane.showInputDialog("Please enter the captcha value:"); ``` `JoptionPane`彈出一個標準對話框,`showInputDialog`提示用戶進行某些輸入。 用戶輸入顯示的驗證碼并單擊“確定”后,它將被保存到字符串`captchaVal`中。 ```java driver.findElement(By.id("recaptcha_response_field")).sendKeys(captchaVal); ``` 保存在“`captchaVal`”中的該值將在 ID 所在的驗證碼文本框中輸入。 ![captcha_popup](https://img.kancloud.cn/9a/9e/9a9e54e7b424891fa7c11a407f6efeb4_713x433.png) 在 JUnit 窗格中,綠色條顯示測試用例已成功執行。 ![captcha_output](https://img.kancloud.cn/2d/ad/2dadd3efb402ee489bad3df50f3364f3_577x167.png) 下圖顯示了在 Firefox 瀏覽器中執行的最終輸出。 ![captcha_output_firefox](https://img.kancloud.cn/ef/97/ef976bc92f6da79ef9cd818201b82e2b_541x356.png) 我讓你們全都受了驗證碼! 在另一篇文章中再見。 祝你有美好的一天!
                  <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>

                              哎呀哎呀视频在线观看