【问题标题】:How to do right click in selenium test如何在硒测试中进行右键单击
【发布时间】:2011-09-20 14:51:54
【问题描述】:

我在接缝中使用了 recursiveTreeNodesAdaptor。我想通过 contextMenu 添加子树,当用户单击树的右节点打开上下文菜单并单击左然后打开模式面板时。我想这样做。

当我尝试编写 selenium 测试此流程时,我不会点击绑定并打开 contextMenu。我尝试 selenium.contextmenu(xpath) 但我失败了。

那么,我怎样才能点击右侧


我尝试使用用户扩展来模拟右键单击。我的功能如下:

Selenium.prototype.doContextMenuClick = function(element){
var evt = document.createEvent('MouseEvents');

var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE

evt.initMouseEvent('contextmenu', true, true,
     document.defaultView, 1, 0, 0, 0, 0, false,
     false, false, false, RIGHT_CLICK_BUTTON_CODE, null);

if (document.createEventObject){
    // dispatch for IE
return document.fireEvent('onclick', evt);
}
else{
   // dispatch for firefox + others
   return !document.dispatchEvent(evt);
}};

我设法从 IDE 调用该函数。但是,现在,我收到错误“this.waitForCondition 不是函数”。怎么了?你有什么主意吗?

提前致谢。

【问题讨论】:

    标签: selenium richfaces contextmenu right-click


    【解决方案1】:

    尝试在该元素上使用 fireEvent。 您还应该查看this post,这似乎与同一问题有关。

    【讨论】:

      【解决方案2】:

      最新的 selenium 有一个名为 OpenQA.Selenium.Interactions 命名空间的命名空间。看看here

      见我的另一篇帖子here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-25
        • 1970-01-01
        • 1970-01-01
        • 2020-04-04
        • 1970-01-01
        相关资源
        最近更新 更多