Selenium WebDriver - How to Holds down the RIGHT mouse button?

不羁的心 提交于 2019-12-04 09:29:15

You can use robot class to perform same. For Right click use Button3 and for middle use Button2

Code for Right click

Robot robot=new Robot();
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);

Code for Middle Button

Robot robot=new Robot();
robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

If its not a browser or windows menu ,If its a something like a web context menu you can use following code its in c# java must be similar

Actions actions = new Actions(WebDriver);
actions.ContextClick(webElement)
                                               .SendKeys(Keys.Down)
                                               .SendKeys(Keys.Down)
                                               .Build()
                                               .Perform();

you can use a combination of actions.ClickAndHold() and actions.MoveToElement() to create a drag effect , I use these to move portal widgets

Please tell me what type of menu you are working on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!