<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/double-click-and-right-click-selenium.html](https://www.guru99.com/double-click-and-right-click-selenium.html) ## 雙擊硒 可以使用 Actions 類在 Selenium Web 驅動程序中雙擊動作。 Actions 類是 Selenium Web 驅動程序中的預定義類,用于執行多個鍵盤和鼠標操作,如右鍵單擊,拖放等。 使用 Actions 類雙擊 Selenium ``` Actions actions = new Actions(driver); WebElement elementLocator = driver.findElement(By.id("ID")); actions.doubleClick(elementLocator).perform(); ``` * 最初,我們需要通過將驅動程序實例作為參數傳遞來實例化 Actions 類的對象 * 使用 find element 命令,我們需要找到要雙擊的元素的定位符 * 使用 Actions 類的預定義雙擊方法,我們需要在 Web 元素上執行雙擊操作 ## 右鍵單擊 Selenium 可以使用 Actions 類在 Selenium Web 驅動程序中右鍵單擊動作。 右鍵單擊操作在 Selenium 中也稱為“上下文單擊”。 Actions 類提供的預定義方法上下文單擊用于執行右鍵單擊操作。 下面的代碼演示了使用 Actions 類的右鍵單擊操作。 ``` Actions actions = new Actions(driver); WebElement elementLocator = driver.findElement(By.id("ID")); actions.contextClick(elementLocator).perform(); ``` ## 雙擊示例 **測試場景** * 啟動 URL: [http://demo.guru99.com/test/simple_context_menu.html](http://demo.guru99.com/test/simple_context_menu.html) * 雙擊標有“雙擊我以查看警報”的按鈕 * 單擊顯示的警報上的 OK 按鈕。 **代碼:** ``` package test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.Alert; public class DobuleClickDemo { public static void main(String[] args) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","X://chromedriver.exe"); driver= new ChromeDriver(); //Launch the Application Under Test (AUT) driver.get("http://demo.guru99.com/test/simple_context_menu.html"); driver.manage().window().maximize(); driver.get("http://demo.guru99.com/test/simple_context_menu.html"); driver.manage().window().maximize(); //Double click the button to launch an alertbox Actions action = new Actions(driver); WebElement link =driver.findElement(By.xpath("//button[text()='Double-Click Me To See Alert']")); action.doubleClick(link).perform(); //Switch to the alert box and click on OK button Alert alert = driver.switchTo().alert(); System.out.println("Alert Text\n" +alert.getText()); alert.accept(); //Closing the driver instance //driver.quit(); } } ``` **結果:** 單擊標有“雙擊我以查看警報”的按鈕,并顯示彈出窗口 ![](https://img.kancloud.cn/b0/11/b01108389e71251656bc17231d2a7cc5_1326x643.png) 在 Eclipse 中,您會在控制臺中看到輸出 ![](https://img.kancloud.cn/eb/3e/eb3e87687fa94afc2ca2efc8f1048761_408x312.png) ## 右鍵單擊示例 **測試方案:** 1. 啟動 URL: [http://demo.guru99.com/test/simple_context_menu.html](http://demo.guru99.com/test/simple_context_menu.html) 2. 在按鈕上執行右鍵單擊操作:右鍵單擊我 3. 單擊顯示的右鍵單擊列表上的“編輯”鏈接 4. 在顯示的警報上單擊確定按鈕 5. 關閉瀏覽器 **Code:** ``` package test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; public class ContextClick { public static void main(String[] args) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.chrome.driver","X://chromedriver.exe"); driver= new ChromeDriver(); //Launch the Application Under Test (AUT) driver.get("http://demo.guru99.com/test/simple_context_menu.html"); driver.manage().window().maximize(); // Right click the button to launch right click menu options Actions action = new Actions(driver); WebElement link = driver.findElement(By.cssSelector(".context-menu-one")); action.contextClick(link).perform(); // Click on Edit link on the displayed menu options WebElement element = driver.findElement(By.cssSelector(".context-menu-icon-copy")); element.click(); // Accept the alert displayed //driver.switchTo().alert().accept(); // Closing the driver instance //driver.quit(); } } ``` **Result:** [![](https://img.kancloud.cn/64/7d/647d90337bfff928c7ec6928afd5d2a3_642x423.png) ](/images/1/011119_1109_Doubleclick3.png) ## 摘要: * Selenium 中的 Actions 類主要用于執行復雜的鍵盤和鼠標操作。 因此,與 Javascript 相比,Actions 類在執行 Selenium 中的右鍵單擊和雙擊之類的操作時更為可取。 * 在元素上單擊鼠標右鍵以打開新菜單時,通常使用鼠標右鍵操作。 可以使用預定義的命令在 Selenium Web 驅動程序中進行右鍵單擊操作。上下文單擊,如下所述 ``` Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID ("Element ID")); action.contextClick(link).perform(); ``` * 雙擊操作后 Web 元素的狀態更改時,將使用雙擊操作。 Selenium Web 驅動程序中的雙擊操作可以使用預定義的命令雙擊完成,如下所述 ``` Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID ("Element ID")); action. doubleClick (link).perform(); ```
                  <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>

                              哎呀哎呀视频在线观看