Selenium 2.2 中的上下文单击

发布于 2024-11-27 11:10:02 字数 1264 浏览 1 评论 0原文

在 Selenium 2 中使用高级用户交互 API 打开自定义上下文菜单时遇到问题 (http:// code.google.com/p/selenium/wiki/AdvancedUserInteractions)。

这是 C# 代码:

var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.flickr.com/photos/davidcampbellphotography/4581594452/");
IWebElement photoDiv = driver.FindElement(By.Id("photo"));

Actions actions = new Actions(driver);
var context = actions.ContextClick(photoDiv).Build();
context.Perform();

该代码仍然不会打开上下文菜单,而只是单击图像。

还有许多其他交互工作正常,例如 这篇博文

我在 Windows XP 上使用 Firefox 5,Selenium 版本 2.2。

预先感谢您提供有关如何使其发挥作用的任何建议。

更新: 但是,此处的代码执行相同的操作(左键单击而不是上下文单击)。

ILocatable loc = (ILocatable)photoDiv;
IMouse mouse = ((IHasInputDevices)driver).Mouse;
mouse.ContextClick(loc.Coordinates);
mouse.MouseMove(loc.Coordinates, 15, 15);

看起来像一个错误。

Got problem with opening custom context menu using advanced user interactions API in Selenium 2 (http://code.google.com/p/selenium/wiki/AdvancedUserInteractions).

Here is C# code:

var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.flickr.com/photos/davidcampbellphotography/4581594452/");
IWebElement photoDiv = driver.FindElement(By.Id("photo"));

Actions actions = new Actions(driver);
var context = actions.ContextClick(photoDiv).Build();
context.Perform();

Still this code doesn't open context menu but simply clicks on the image.

Still many other interactions work fine, like those at this blogpost.

I'm using Firefox 5 on Windows XP, Selenium version 2.2.

Thanks in advance for any suggestions how to make it work.

UPDATE:
However, the code from here does the same (left click instead of context click).

ILocatable loc = (ILocatable)photoDiv;
IMouse mouse = ((IHasInputDevices)driver).Mouse;
mouse.ContextClick(loc.Coordinates);
mouse.MouseMove(loc.Coordinates, 15, 15);

Looks like a bug.

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

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

发布评论

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

评论(2

挽清梦 2024-12-04 11:10:02

您是否尝试过使用机器人点击,虽然它们不是最有效的方式,但只要浏览器窗口是顶部窗口,它就会点击您设置的坐标

    Robot robot = new Robot();
    robot.mouseMove(650, 590);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

也许这会对您有所帮助:-)

Have you tried using a robot click, Although they're not the most efficient way of doing so, but as long as the browser window is the top window it'll click the co-ordinates you set

    Robot robot = new Robot();
    robot.mouseMove(650, 590);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

Maybe this will help you :-)

孤城病女 2024-12-04 11:10:02

这似乎就是那个错误
它在用户组

This seems to be that bug.
It is stated in the user group here, though the bug is about double click.

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