473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Selenium + C# + hover = difficult

Hi!

For a couple of days I've been trying to use Selenium to automate testing of a website. This fails because of a hidden menu item that is only displayed when the parent item in the menu is hovered.

The website I'm trying to test on is found here: http://www.sweetarabians.com/.

The parent menu item is "Stallions", which is contained in a HTML LI item. This is also the item to be hovered.

Here is my C# code being used:
Expand|Select|Wrap|Line Numbers
  1. using NUnit.Framework;
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4. using OpenQA.Selenium.Firefox;
  5. using OpenQA.Selenium.Interactions;
  6. using OpenQA.Selenium.Interactions.Internal;
  7. using OpenQA.Selenium.Support.UI;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.UI;
  13. using System.Web.UI.WebControls;
  14.  
  15. namespace Selenium
  16. {
  17.     [TestFixture]
  18.     public partial class Default : System.Web.UI.Page
  19.     {
  20.         public Int16 SweetArabians1()
  21.         {
  22.             Int16 result;
  23.             IWebDriver ff_driver = new FirefoxDriver();
  24.  
  25.             ff_driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
  26.             ff_driver.Navigate().GoToUrl("http://www.sweetarabians.com/");
  27.  
  28.             var stallions_li = ff_driver.FindElement(By.ClassName("page-item-6"));
  29.             Actions action1 = new Actions(ff_driver);
  30.             action1.MoveToElement(stallions_li).Perform();
  31.  
  32.             var stallions_link = stallions_li.FindElement(By.LinkText("Stallions"));
  33.             Actions action2 = new Actions(ff_driver);
  34.             action2.MoveToElement(stallions_link).Perform();
  35.  
  36.             WebDriverWait wait = new WebDriverWait(ff_driver, TimeSpan.FromSeconds(10));
  37.             var hero_link = wait.Until((d) => { return d.FindElement(By.LinkText("Sweet Hero")); });
  38.  
  39.             ff_driver.FindElement(By.LinkText("Sweet Hero")).Click();
  40.  
  41.             # Wait a few seconds and then do some testing of the to-be-loaded page here...
  42.  
  43.             if (ff_driver != null)
  44.             {
  45.                 ff_driver.Close();
  46.             };
  47.         }
  48.  
  49.         protected void Page_Load(object sender, EventArgs e)
  50.         {
  51.             SweetArabians1();
  52.         }
  53.     }
  54. }
  55.  
This doesn't make the submenu appear at all and I don't understand what I'm doing wrong. Does anybody have a clue? Any help is appreciated.

Best regards

David
Oct 30 '12 #1

✓ answered by davidraimosson

After some further struggling I think I know what the problem is. Namely that the FirefoxDriver uses synthetic events instead of native events. Because of that the hovering was never triggered. I got it to work with the InternetExplorerDriver which always uses native events.

If I could find out how to use native events with the FirefoxDriver, which should be possible, then I suppose it would solve the problem as well.

2 3828
I've tried to simulate a hover on the following simple HTML code as well, without success:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html><head>
  3. <title>Test</title>
  4. <style type="text/css">
  5. <!--
  6.  
  7. #test {
  8.     background: #00ff00;
  9.     display: block;
  10.     height: 20px;
  11.     width: 200px;
  12. }
  13.  
  14. #test:hover > div {
  15.     display: block;
  16. }
  17.  
  18. #inside {
  19.     display: none;
  20. }
  21.  
  22. -->
  23. </style>
  24. </head>
  25. <body>
  26. <div id="test">
  27.     Hover me!<br>
  28.     <div id="inside">
  29.         <a href="about:blank">Go to blank page</a>
  30.     </div>
  31. </div>
  32. </body>
  33. </html>
Oct 31 '12 #2
After some further struggling I think I know what the problem is. Namely that the FirefoxDriver uses synthetic events instead of native events. Because of that the hovering was never triggered. I got it to work with the InternetExplorerDriver which always uses native events.

If I could find out how to use native events with the FirefoxDriver, which should be possible, then I suppose it would solve the problem as well.
Oct 31 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Gerry Vandermaesen | last post by:
Hi, I'm trying out the following: CSS .className { width: 30px; height: 30px; border: 1px solid black; }
0
by: yonatan | last post by:
hello all. I've been working on a website (windows/PHP/APACHE/MYSQL), doing both the coding and testing/QA. for unit tests, I use jsUnit (javascript), and simpleTest (PHP). when I needed...
1
by: TomT | last post by:
I am having a difficult time solving a problem. Whenever I use :hover in a certain <div> the page shrinks in IE6. Of course, this problem does not exist with other browsers. It is even more vexing...
5
by: Bubba | last post by:
I need to use an inline css tag for a few links that will not behave like the a:link and a:hover attributes in my stylesheet. I want to add a special link color with underline and a mouseover...
1
by: sphinxz | last post by:
Hi all, I have to test the functionality of a Web application which navigates between Https and Http . I am using Selenium RC with the latest snapshot (0.92) but still gettting the error ...
0
by: sk27ahmed | last post by:
Hi Is any one tell me how to open "www.mail.yahoo.com" by sending it username and password via code by using C#.Net and NUnit(Selenium software)? I want to show yahoo inbox automatically when I run...
1
by: Selva123 | last post by:
WWW::Selenium terminates program on object not found - not expected -Expects something like try- catch in java Hi All, Greetings. I am automating testcases with Selenium RC and PERL using...
0
by: somsub | last post by:
Hi All, I am facing a problem while running a perl script through selenium RC server . I recorded oone log in test case with slenium IDE and run it after that with the ide only and it worked...
1
by: Erik Anderson | last post by:
Hey I am trying to get the hang of both Python and Selenium RC at the same time and having a bit of difficulty and was wondering if anyone here could assist me validating my Python Script. I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.