We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Right-click menus, pause between actions, and custom action sequences
In this practice lab, you will learn advanced Action API techniques beyond basic clicks and keyboard input:
What it does
Performs a right-click on the specified element, typically opening a context menu with additional options.
When to use it
What it does
Inserts a deliberate pause in the action sequence for a specified duration (in milliseconds).
When to use it
You can combine any Actions methods to create complex, multi-step gestures:
Complex Form Navigation
Click → Type → Tab → Type → Shift+Tab → Modify → Enter
Drag with Pause
ClickAndHold → MoveByOffset → Pause → MoveByOffset → Release
Multi-Select
Click Item1 → KeyDown(Ctrl) → Click Item2 → Click Item3 → KeyUp(Ctrl)
Practice advanced gestures with these interactive demos:
Sequence Status:
Not started
This demonstrates how pause() adds deliberate delays between actions in a sequence.
Right-click the area above or run the pause sequence to see advanced gestures in action!
If you were doing this manually:
Your Selenium code will automate these behaviors using contextClick() and pause().
12345678910111213141516171819202122232425262728293031323334353637WebElement contextArea = driver.findElement(By.id("context-area"));
WebElement copyOption = driver.findElement(By.linkText("Copy"));
Actions actions = new Actions(driver);
// 1. Right-click to open context menu
actions.contextClick(contextArea).perform();
// 2. Wait for menu to appear and click option
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOf(copyOption));
actions.click(copyOption).perform();
// 3. Complex sequence with pause
WebElement button1 = driver.findElement(By.id("button1"));
WebElement button2 = driver.findElement(By.id("button2"));
actions
.click(button1)
.pause(Duration.ofMillis(1000))
.click(button2)
.perform();
// 4. Multi-select with Ctrl key
WebElement item1 = driver.findElement(By.id("item1"));
WebElement item2 = driver.findElement(By.id("item2"));
WebElement item3 = driver.findElement(By.id("item3"));
actions
.click(item1)
.keyDown(Keys.CONTROL)
.click(item2)
.click(item3)
.keyUp(Keys.CONTROL)
.perform();
driver.quit();Always use explicit waits after contextClick() to ensure the context menu has appeared before trying to interact with menu items. Context menus can take time to render.
Use pause() sparingly. In most cases, explicit waits (waiting for elements to be visible/clickable) are better than fixed time delays, as they make tests faster and more reliable.
When building complex gesture sequences, test each step individually first. Once each piece works, chain them together. This makes debugging much easier than trying to fix a long chain all at once.