마우스 오른쪽 버튼을 클릭하고 Double 클릭 Selenium
⚡ 스마트 요약
마우스 오른쪽 버튼을 클릭하고 Double 클릭 Selenium 마우스 동작은 Actions 클래스를 통해 자동화됩니다. 이 튜토리얼에서는 두 가지 동작 모두 작동하는 모습을 보여줍니다. Java 코드, 실제 테스트 시나리오, 그리고 그것들을 구동하는 방법론 Selenium 웹드라이버.

마우스 오른쪽 버튼을 클릭하세요. Selenium
오른쪽 클릭 동작 Selenium WebDriver는 Actions 클래스를 사용하여 구현됩니다. 이 작업은 컨텍스트 클릭이라고도 합니다. 미리 정의된 contextClick() Actions 클래스의 메서드는 마우스 오른쪽 클릭을 수행합니다. 기본 구문은 다음과 같습니다.
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.contextClick(elementLocator).perform();
마우스 오른쪽 버튼을 클릭하는 방법 Selenium
아래 시나리오는 다음을 시작합니다. Guru99 데모 페이지에서 마우스 오른쪽 버튼을 클릭하고 나타나는 컨텍스트 메뉴에서 옵션을 선택합니다.
테스트 시나리오 :
- 쏘다: https://demo.guru99.com/test/simple_context_menu.html
- "오른쪽 클릭" 버튼을 마우스 오른쪽 버튼으로 클릭하세요.
- 표시된 메뉴에서 편집 링크를 클릭하세요.
- 알림창에서 확인을 클릭하세요.
- 브라우저를 닫습니다
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();
driver.get("https://demo.guru99.com/test/simple_context_menu.html");
driver.manage().window().maximize();
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.cssSelector(".context-menu-one"));
action.contextClick(link).perform();
WebElement element = driver.findElement(By.cssSelector(".context-menu-icon-copy"));
element.click();
}
}
결과 : 컨텍스트 메뉴가 나타나고 [편집] 옵션이 선택됩니다.
Double 클릭 Selenium
동일한 행동 기반 패턴을 따르면, Double 클릭 Selenium WebDriver는 미리 정의된 것을 사용합니다. doubleClick() 메서드입니다. Actions 클래스는 마우스 오른쪽 클릭, 드래그 앤 드롭, 마우스 오버와 같은 복합적인 마우스 및 키보드 작업을 위한 표준 도우미 클래스입니다.
Actions actions = new Actions(driver);
WebElement elementLocator = driver.findElement(By.id("ID"));
actions.doubleClick(elementLocator).perform();
실행 흐름은 다음과 같습니다.
- 드라이버 인스턴스를 사용하여 Actions 객체를 인스턴스화합니다.
- 대상 요소를 찾으세요
findElement. - 상담 예약 번호
doubleClick()그리고 체인perform()실행하다.
방법 Double 클릭 Selenium
다음 시나리오는 더블 클릭이 트리거되는 상황을 보여줍니다. Java스크립트는 경고를 표시하고 프로그램적으로 이를 확인합니다.
테스트 시나리오 :
- 쏘다: https://demo.guru99.com/test/simple_context_menu.html
- Double 버튼을 클릭하세요Double-알림을 보려면 클릭하세요
- 알림창에서 확인을 클릭하세요.
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;
import org.openqa.selenium.Alert;
public class DoubleClickDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "X://chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://demo.guru99.com/test/simple_context_menu.html");
driver.manage().window().maximize();
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.xpath("//button[text()='Double-Click Me To See Alert']"));
action.doubleClick(link).perform();
Alert alert = driver.switchTo().alert();
System.out.println("Alert Text\n" + alert.getText());
alert.accept();
}
}
결과 : 알림창이 뜨고 알림 내용이 출력됩니다. Eclipse 콘솔.



