如何在硒测试中右键单击

发布于 2024-12-05 16:23:09 字数 874 浏览 4 评论 0原文

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

当我尝试编写硒测试此流程时,我不会单击来装配并打开 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 不是函数”。怎么了?你有什么想法吗?

提前致谢。

I have using recursiveTreeNodesAdaptor in seam. And I want to add child this tree via contextMenu and when user click right node of tree open context menu and click left then open modal panel. I want to do this.

When I try to write selenium test this flow I dont click to rigt and open contextMenu. I try to selenium.contextmenu(xpath) but i'm fail.

So, How can I click to right


I tried to simulate right click with user extension. My function is below:

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);
}};

I managed to call the function from IDE. But, now, I get the error "this.waitForCondition is not a function". What's wrong? Do you have any idea?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

同尘 2024-12-12 16:23:09

尝试在该元素上使用 fireEvent 。
您还应该看看这篇文章,它似乎差不多问题。

Try using fireEvent on that element.
You should also take a look at this post which seems to be about the same issue.

南风起 2024-12-12 16:23:09

最新的 selenium 有一个名为 OpenQA.Selenium.Interactions Namespace 的命名空间。请查看此处

请参阅我的另一篇文章此处

The latest selenium has a namespace called OpenQA.Selenium.Interactions Namespace. check it out here.

see my other post here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文