how can you do right click using selenium?

2019-02-09 00:56发布

im trying to preform a right click using selenium, any thoughts on how to do this?

5条回答
别忘想泡老子
2楼-- · 2019-02-09 01:26

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-09 01:27

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.

查看更多
Summer. ? 凉城
4楼-- · 2019-02-09 01:29

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.

查看更多
你好瞎i
5楼-- · 2019-02-09 01:33

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();
查看更多
Rolldiameter
6楼-- · 2019-02-09 01:38

Selenium is offering a method for right click - ContextClick:

        public void RightClick(IWebElement target)
        {
            var builder = new Actions(driver);
            builder.ContextClick(target);
            builder.Perform();
        }
查看更多
登录 后发表回答