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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 最大化 Selenium 中的瀏覽器 > 原文: [https://www.guru99.com/maximize-resize-minimize-browser-selenium.html](https://www.guru99.com/maximize-resize-minimize-browser-selenium.html) 在本教程中,您將學習如何使用 Selenium Webdriver 最大化,最小化或調整瀏覽器的大小。 通過使用 maximum()方法和尺寸調整瀏覽器大小的不同場景進行了解釋。 這是我們涵蓋的內容: * [為什么要在 Selenium Automation 中最大化瀏覽器?](#1) * [如何最大化硒中的瀏覽器](#2) * [示例:使用 Selenium Web 驅動程序](#3)調整瀏覽器的大小 * [示例:使用 Web 驅動程序最大化瀏覽器窗口。](#4) * [示例:使用 Web 驅動程序最小化瀏覽器窗口。](#5) ## 為什么要在 Selenium Automation 中最大化瀏覽器? *如果瀏覽器未最大化,則硒可能無法識別 Web 應用程序上的元素,從而使框架失效。* 因此,最大化瀏覽器是 Selenium 框架中非常重要的部分。 最佳做法是在自動化任何 Web 應用程序時最大化瀏覽器。 當用戶執行 Selenium 框架或任何腳本時,瀏覽器可能未處于全屏狀態,因此您需要最大化瀏覽器以查看 Web 應用程序的所有元素。 最好在腳本開始時最大化瀏覽器,以使腳本成功執行而沒有任何錯誤。 ## 如何在 Selenium 中最大化瀏覽器 要最大化瀏覽器窗口,您需要調用驅動程序類的 Window 接口的 maximum()方法。 ``` void maximize() – This method is used to maximize the current browser. ``` ![Maximize Webdriver](https://img.kancloud.cn/c8/4d/c84d7efcc3cfbba5c5720cfa5cc68809_508x290.png) 您可以根據方案的要求自定義瀏覽器的大小。 Selenium Webdriver 沒有提供任何最小化瀏覽器的方法,也沒有這種直接方法。 您需要使用調整大小方法來最小化瀏覽器。 ``` void setSize() – This method is used to set the size of the current browser. Dimension getSize() – This method is used to get the size of the browser in height and width. It returns the dimension of the browser. Point setPosition() – This method is used to set the position of the current browser. ``` ## 示例:使用 Selenium Web 驅動程序調整瀏覽器的大小 ### a)帶有說明的硒腳本。 **腳本描述:**在下面的 Selenium 腳本中,顯示了使用 testNG 框架調整瀏覽器的大小,該場景的步驟如下: 1. 打開 chrome 瀏覽器。 2. 啟動站點。 3. 等待幾秒鐘以查看調整大小操作。 4. 關閉瀏覽器。 ``` import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Resize { public static void main(String args[]) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.get("https://www.guru99.com/"); Dimension d = new Dimension(300,1080); //Resize current window to the set dimension driver.manage().window().setSize(d); //To Delay execution for 10 sec. as to view the resize browser Thread.sleep(10000); //Close the browser driver.quit(); } } ``` #### b)輸出分析 打開 chrome 瀏覽器,調整瀏覽器的大小,等待幾秒鐘,然后關閉瀏覽器。 ## 示例:使用 Web 驅動程序最大化瀏覽器窗口。 ### a) Selenium script with explanation. **腳本描述:**在下面的 Selenium 腳本中,顯示了使用 testNG 框架最大化瀏覽器的情況,該場景的步驟如下: 1. 打開 chrome 瀏覽器。 2. 啟動站點。 3. 等待幾秒鐘,以查看最大化操作。 4. 關閉瀏覽器。 ``` import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Maximize { public static void main(String args[]) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.get("https://www.guru99.com/"); //Resize current window to the set dimension driver.manage().window().maximize(); //To Delay execution for 10 sec. as to view the maximize browser Thread.sleep(10000); //Close the browser driver.quit(); } } ``` #### b) Output Analysis 打開 chrome 瀏覽器,最大化瀏覽器,等待幾秒鐘,然后關閉瀏覽器。 ## 示例:使用 Web 驅動程序最小化瀏覽器窗口。 ### a) Selenium script with explanation. **腳本描述:**在下面的 Selenium 腳本中,使用 testNG 框架最小化了瀏覽器,該場景的步驟如下: 1. 打開 chrome 瀏覽器。 2. 啟動站點。 3. 等待幾秒鐘以查看最小化操作。 4. 關閉瀏覽器。 ``` import org.openqa.selenium.Point; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Minimize { public static void main(String args[]) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","E://Selenium//Selenium_Jars//chromedriver.exe"); driver= new ChromeDriver(); // Launch the application driver.get("https://www.guru99.com/"); Point p = new Point(0,3000); //Minimize the current window to the set position driver.manage().window().setPosition(p); //To Delay execution for 10 sec. as to view the minimize browser //you can view in the taskbar below of the screen. Thread.sleep(10000); //Close the browser driver.quit(); } } ``` **注意:**如果用戶要使用 Firefox 瀏覽器,則需要在以下所有上述 3 種場景腳本中設置 FirefoxDriver 的屬性并創建 FirefoxDriver 對象而不是 ChromeDriver 對象,如下所示: ``` System.setProperty("webdriver.gecko.driver","E://Selenium//Selenium_Jars//geckodriver.exe "); driver= new FirefoxDriver(); ``` #### b) Output Analysis 打開 chrome 瀏覽器,最小化瀏覽器,等待幾秒鐘,然后關閉瀏覽器。 ## 故障排除 * 使用最新版本的 Selenium Jars,chromedriver,木偶驅動程序和 IEdriver 等。 * 檢查硒罐和使用的瀏覽器的兼容性。 #### 摘要 * 在以上教程中,我們說明了通過不同場景調整瀏覽器的大小,例如根據項目框架中針對不同功能的要求最大化,最小化和調整大小。 * 在第一種情況下,我們顯示了使用硒調整瀏覽器的大小。 ``` Dimension d = new Dimension(300,1080); driver.manage().window().setSize(d); ``` * 在第二種情況下,我們展示了硒中瀏覽器的最大化。 ``` driver.manage().window().maximize(); ``` * 在第三種情況下,我們展示了最小化硒瀏覽器。 ``` Point p = new Point(0,3000); driver.manage().window().setPosition(p); ```
                  <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>

                              哎呀哎呀视频在线观看