How to right click using Selenium WebDriver

1 min


644
644 points
How to right click using Selenium webdriver
How to right click using Selenium webdriver

How to right click using Selenium WebDriver

I’m sure most of you had to test an application that has functionalities by triggering the action with a right-click menu.

Basically this menus are system level menus and are untouchable by Selenium commands.

So the question is – How do I test it ?

Java solution:

To select the option within a context menu , you’ll have to move the mouse with a use of Key down:

Actions action= new Actions(driver);
action.contextClick(link).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
select context menu

C# How to right click using Selenium WebDriver:

 

Actions() builder = new Actions();
builder.ContextClick(webLocator).Build().Perform();
how to right click c# solution

Ruby How to right click using Selenium WebDriver:

driver.action.move_to(weblocator,100,100).click.context_click.perform
ruby how to right click

I know some of the Test engineers use frameworks in top of Selenium eg : Capybara so there it’s a way to do it as well.

 @session.driver.browser.action.context_click(self.native).perform
ruby capybara right click

You san simply test the examples above with the following scenario:

  • Open a Firefox browser.
  • Navigate to the URL (https://google.com).
  • Now right click on the search field 🙂

To learn more about context menus, you can read Building a Custom Right-Click (Context) Menu with JavaScript

And for more details about Actions ,  and java script you can follow the Selenium documentation here.

Happy Hunting!


Like it? Share with your friends!

644
644 points

What's Your Reaction?

cute cute
0
cute
scary scary
0
scary
wtf wtf
3
wtf
geek geek
1
geek
WIN WIN
0
WIN
Love Love
0
Love
OMG OMG
0
OMG
Angry Angry
0
Angry
Lol Lol
0
Lol
Test engineer

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Story