11

Is there anybody who can provide a c# example of how to get past the known Selenium issue involving the css pseudo-class :hover?

Essentially, i am working on regression testing for a website startin w/ the selenium IDE (and building the rest of my code in Visual Studio 2008), and need to hover over a div, make it appear, and click a link inside said div.

All of my efforts have failed however, and it seems that many have this issue, with no solution.

Thanks in advance!

mac
  • 42,153
  • 26
  • 121
  • 131
spacebed
  • 329
  • 2
  • 4
  • 14

1 Answers1

13

Okay! So I appreciate the help (I had actually seen that thread, but the .hover() class has been deprecated, and I could not get it to work. I did, however, just find a solid workaround.

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

Also, you will need to have a couple using statements included.

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

Hope This Helps!

sfarbota
  • 2,619
  • 1
  • 22
  • 30
spacebed
  • 329
  • 2
  • 4
  • 14
  • 2
    Thanks very much for including the 'using' statements. Without it, I've been having a tough time trying to search for a solution to mouseover using Webdriver (C#) on IE. –  Aug 28 '12 at 15:33
  • Just the problem I had. Thanks for this. – Frederik Oct 21 '15 at 12:06