how can you do right click using selenium?

落爺英雄遲暮 提交于 2019-11-30 12:07:27
Felix Kling

Please see docroots's answer for selenium.

To generally simulate a right click in JavaScript, have a look at JavaScript simulate right click through code.

Peter Agnew

According to the OpenQA.Selenium.Interactions Namespace.

// step 1 - select the element you want to right-click
var elementToRightClick = this.Driver.FindElement(By.Id("elementtoclickonhasthisid"));
// step 2 - create and step up an Actions object with your driver
var action = new OpenQA.Selenium.Interactions.Actions(this.Driver);
action.ContextClick(elementToRightClick);
// step 3 - execute the action
action.Perform();

it appears that for my issue (an element that opens a popup after a right click), using selenium's : mouse_down_right() and then mouse_up_right() worked as well. thanks.

Luna007

I've tried ActionSequence and it worked.

ContextClick function is not found, you should use click.

So, it should be as follows:

driver.actions().click(element,2).perform();

The element is your web element, 2 means right click.

Selenium is offering a method for right click - ContextClick:

        public void RightClick(IWebElement target)
        {
            var builder = new Actions(driver);
            builder.ContextClick(target);
            builder.Perform();
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!