【问题标题】:How to do a mouse over using selenium webdriver to see the hidden menu without performing any mouse clicks?如何使用 selenium webdriver 将鼠标悬停在不执行任何鼠标单击的情况下查看隐藏菜单?
【发布时间】:2013-12-03 15:45:32
【问题描述】:

如何使用 selenium webdriver 进行鼠标悬停/悬停以查看隐藏菜单而不执行任何鼠标点击?

我正在测试的网站上有一个隐藏菜单,该菜单仅在鼠标悬停/悬停时出现。 注意:如果执行任何点击,页面会被重定向,所以请提出一个不点击的解决方案

我试过了:

IWebDriver driver = new FirefoxDriver()
Actions builder = new Actions(driver)
builder.MoveToElement(driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")))
       .Click().Build().Perform();

【问题讨论】:

    标签: c# selenium-webdriver automated-tests


    【解决方案1】:

    试试这个?

    // this makes sure the element is visible before you try to do anything
    // for slow loading pages
    WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    var element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(elementId)));
    
    Actions action  = new Actions(driver);
    action.MoveToElement(element).Perform();
    

    【讨论】:

    • 哇!我从来不知道使用那个 TimeSpan 类。谢谢!
    • 但是最后还是会打开另一个浏览器寡妇
    • 我不明白你的意思
    【解决方案2】:

    是的,你发布的问题是关于工具提示的

    执行鼠标悬停然后捕获其属性值

    仔细观察您的 HTML 代码,手动将鼠标指针移动到元素上并观察您的隐藏文本显示在哪个属性值中

    Actions builder = new Actions(driver)
    builder.MoveToElement(driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")))
           .Click().Build().Perform();
    
    
    String value=driver.FindElement(By.Id("Content_AdvertiserMenu1_LeadsBtn")).getAttribute("attribute value in which hidden text presents");
    

    【讨论】:

      【解决方案3】:

      你需要使用 - 使用 OpenQA.Selenium.Interactions;

      【讨论】:

        【解决方案4】:

        只是想提一下,最后的解决方法可能是尝试 javascript 鼠标悬停模拟。

        各种语言的解决方案在这里发布:http://code.google.com/p/selenium/issues/detail?id=2067

        【讨论】:

          【解决方案5】:

          要做一个Mouse Hover 使用Selenium webdriver 来查看隐藏菜单而不执行任何鼠标点击你需要确保所需的ElementIsVisible() 诱导WebDriverWait 和使用Actions Class 方法如下:

          using OpenQA.Selenium.Interactions;
          
          var element = new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(By.Id("elementID")));
          new Actions(driver).MoveToElement(element).Perform();
          

          在一行中:

          new Actions(driver).MoveToElement(new WebDriverWait(driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementIsVisible(By.Id("elementID")))).Perform();
          

          参考文献

          您可以在以下位置找到一些相关的详细讨论:

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-02-15
            • 1970-01-01
            • 1970-01-01
            • 2012-08-29
            • 1970-01-01
            • 2016-08-08
            相关资源
            最近更新 更多