Using action, we can perform right click(context click) operation on an object in selenium and also select the menu option using Arrows.down key press as shown in the code below:
Quick Code:
public static void contextMenuSelection(WebElement webElem, int iOption) { //create an instance of actions class Actions action = new Actions(driver); //context click (right click) the element action.contextClick(webElem); for(int i =1;i<=iOption;i++) { //Press send keys for arrow down action.sendKeys(Keys.ARROW_DOWN); } //Press Enter send keys and build and perform the action. action.sendKeys(Keys.ENTER).build().perform(); }
No comments:
Post a Comment