Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A workaround for Selenium 2.0 WebDriver & the :hover pseudoclass

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!

like image 574
spacebed Avatar asked Nov 29 '11 14:11

spacebed


People also ask

Which tool is appropriate to set up a Selenium 2.0 Javascript?

Java: These projects are most easily setup using Maven, which will download Java bindings and all dependencies and create the project for you.

Which tool is appropriate to set up a Selenium 2.2 Java project?

...Android Studio(Java and XML).

Is Selenium 4 backwards compatible?

With that said, Selenium 4 still offers stability because of backwards compatibility. The Java Bindings and the Selenium Server will still provide a mechanism to use the old JSON Wire Protocol. There are multiple contributors to the W3C WebDriver specs, and the whole process can be seen on GitHub.

Which feature is additional in Selenium 2?

Selenium 2 also includes Selenium Server, which supports distributed testing via Selenium Grid. The new Selenium Grid supports testing using both the original Selenium RC API and the new WebDriver API.


1 Answers

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!

like image 148
spacebed Avatar answered Sep 28 '22 17:09

spacebed