如何避免鼠标悬停硒点击() [英] How to avoid MouseOver on Selenium Click()

查看:157
本文介绍了如何避免鼠标悬停硒点击()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Selenium测试情形之一的,我有这个问题,有鼠标悬停效果,我不希望有。这是我做的:

In one of my Selenium test cases, I have the problem that there are MouseOver effects that I don't want to have. This is what I do:


  1. 点击登录按钮(在页面的右上角)

  2. 等待页面加载

  3. 单击在搜索结果中(页面的中间偏右)的购买按钮。

现在的问题是,有一个菜篮子右之间登录和买中间有一个鼠标悬停效果的链接。所以,当我呼吁登录按钮,之后点击()购买按钮,我触发鼠标悬停,这将打开购物车,其中隐藏的购买按钮本身落后的小型预览。

The problem is, that there is a "shopping basket" link with a MouseOver effect right in the middle between "login" and "buy". So when I call Click() on the "login" button and afterwards on the "buy" button, I trigger the MouseOver, which opens a small preview of the shopping cart, which hides the "buy" button behind itself.

这也适用于Firefox和MSIE。在Chrome中,我没有这种效果。

This goes for Firefox and MSIE. In Chrome, I don't have this kind of effect.

任何想法,任何人吗?

推荐答案

我仍然不知道真正的解决方案,但这里的肮脏的解决办法,我使用:

I still don't know the real solution, but here's the dirty workaround I'm using:

public static void Click(this IWebElement element, TestTarget target)
{
    if (target.IsInternetExplorer)
    {
        var actions = new Actions(target.Driver);
        actions.MoveToElement(element).Perform();
        Thread.Sleep(500); // wait for the mouseover popup to appear
        element.SendKeys(Keys.Escape); // to close the popup (if any)
        actions.MoveToElement(element).DoubleClick().Perform(); // simple click is sometimes not enough in IE
    }
    else
    {
        element.Click();
    }
}

这篇关于如何避免鼠标悬停硒点击()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆