【问题标题】:A workaround for Selenium 2.0 WebDriver & the :hover pseudoclassSelenium 2.0 WebDriver 和 :hover 伪类的解决方法
【发布时间】:2011-11-29 14:00:14
【问题描述】:

有没有人可以提供一个 c# 示例来说明如何解决涉及 css 伪类 :hover 的已知 Selenium 问题?

基本上,我正在使用 selenium IDE 开始对网站进行回归测试(并在 Visual Studio 2008 中构建我的其余代码),并且需要将鼠标悬停在 div 上,使其出现,然后单击链接里面说div。

然而我所有的努力都失败了,似乎很多人都有这个问题,没有解决方案。

提前致谢!

【问题讨论】:

标签: c# .net selenium nunit webdriver


【解决方案1】:

好的!所以我很感激帮助(我实际上已经看到了那个线程,但是 .hover() 类已被弃用,我无法让它工作。但是,我确实找到了一个可靠的解决方法。

var phone = driver.FindElement(By.Id("phones"));
var phoneLi = phone.FindElements(By.TagName("li"));
Actions action  = new Actions(driver);//simply my webdriver
action.MoveToElement(phoneLi[1]).Perform();//move to list element that needs to be hovered
var click = action.MoveToElement(phoneLi[1].FindElements(By.TagName("a"))[0];//move to actual button link after the 'Li' was hovered
click.Click();
click.Perform(); //not too sure why I needed to use both of these, but I did. Don't care, it works ;)
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();

此外,您还需要包含几个 using 语句。

using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Support.UI;

希望对您有所帮助!

【讨论】:

  • 非常感谢您包含“使用”语句。没有它,我一直很难在 IE 上使用 Webdriver (C#) 寻找鼠标悬停的解决方案。
  • 只是我遇到的问题。谢谢你。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-23
  • 2019-07-04
  • 1970-01-01
  • 1970-01-01
  • 2011-05-17
  • 2010-10-25
  • 2011-02-22
相关资源
最近更新 更多