468,253 Members | 1,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

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 3569
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

Post your reply

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

Similar topics

5 posts views Thread by Gerry Vandermaesen | last post: by
reply views Thread by yonatan | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.