마우스 오른쪽 버튼을 클릭하고 Double 클릭 Selenium (예시)
오른쪽 클릭 Selenium
오른쪽 클릭 동작 Selenium 웹 드라이버는 Actions 클래스를 사용하여 수행할 수 있습니다. 오른쪽 클릭 작업은 Context Click이라고도 합니다. Selenium. Actions 클래스에서 제공하는 사전 정의된 메서드 컨텍스트 클릭은 오른쪽 클릭 작업을 수행하는 데 사용됩니다. 아래는 Actions 클래스를 사용하여 오른쪽 클릭 작업을 보여주는 코드입니다.
Actions actions = new Actions(driver); WebElement elementLocator = driver.findElement(By.id("ID")); actions.contextClick(elementLocator).perform();
마우스 오른쪽 버튼을 클릭하는 방법 Selenium
테스트 시나리오 :
- URL을 실행하세요: https://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; 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("https://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(); } }
결과 :
Double 클릭 Selenium
Double 클릭 동작 Selenium 웹 드라이버는 Actions 클래스를 사용하여 수행할 수 있습니다. Actions 클래스는 미리 정의된 클래스입니다. Selenium 오른쪽 클릭, 드래그 앤 드롭 등 다양한 키보드와 마우스 작업을 수행하는 데 사용되는 웹 드라이버입니다.
Double 클릭 Selenium Actions 클래스 사용
Actions actions = new Actions(driver); WebElement elementLocator = driver.findElement(By.id("ID")); actions.doubleClick(elementLocator).perform();
- 처음에는 드라이버 인스턴스를 매개변수로 전달하여 Actions 클래스의 객체를 인스턴스화해야 합니다.
- find element 명령을 사용하여 더블클릭하려는 요소의 로케이터를 찾아야 합니다.
- Actions 클래스의 미리 정의된 더블 클릭 방법을 사용하여 웹 요소에 대한 더블 클릭 작업을 수행해야 합니다.
방법 Double 클릭 Selenium
테스트 시나리오
- URL을 실행하세요: https://demo.guru99.com/test/simple_context_menu.html
- Double '라고 표시된 버튼을 클릭하세요.Double-경고를 보려면 나를 클릭하세요'
- 표시된 경고에서 확인(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("https://demo.guru99.com/test/simple_context_menu.html"); driver.manage().window().maximize(); driver.get("https://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(); } }
결과 :
"라고 표시된 버튼Double-알림을 보려면 클릭하세요'를 클릭하면 팝업이 표시됩니다.
In Eclipse, 콘솔에 출력이 표시됩니다.
요약
- 액션 클래스 Selenium 주로 복잡한 키보드 및 마우스 작업을 수행하는 데 사용됩니다. 따라서 Actions 클래스가 다음에 비해 선호됩니다. Javascript 마우스 오른쪽 클릭과 같은 작업을 수행하기 위해 Double 클릭 Selenium.
- 오른쪽 클릭 작업은 주로 요소를 오른쪽 클릭하면 새 메뉴가 열리는 경우에 사용됩니다. 오른쪽 클릭 작업 Selenium 웹 드라이버는 미리 정의된 명령을 사용하여 수행할 수 있습니다. 아래 언급된 대로 Context Click을 클릭합니다.
Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID ("Element ID")); action.contextClick(link).perform();
- Double 클릭 작업은 더블 클릭 작업 후 웹 요소의 상태가 변경될 때 사용됩니다. Double 클릭 작업 Selenium 웹 드라이버는 미리 정의된 명령을 사용하여 수행할 수 있습니다. Double 아래 언급한 대로 클릭하세요.
Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID ("Element ID")); action. doubleClick (link).perform();