Sunday, April 17, 2016

WebDriver MouseHover Actions

WebDriver MouseHover Actions


We will look at two examples of WebDriver mouse hover actions:

Example 1 of WebDriver mouse hover
For the first example we will work with the below simple example of mouse hover. When we mouse hover on Dropdown button, the 3 Sub-Menus open.


If you do inspect element for Dropdown button it looks as below:


Lets look at the code which works with the above Dropdown button and hover on the Dropdown button to open three sub-menus.


Make sure you add "using OpenQA.Selenium.Interactions;" namespace at the top of the code. This namespace needs to be added in order to use the Actions method. We are using Firefox browser. After browser is launched we open the file which contains the code for our Dropdown button. An object named action is being created from Actions class and a driver object is being passed to it. After that we are identifying the Dropdown button. Finally mouse hover action is being done using Perform().

Example 2 of WebDriver mouse hover
In our second example we will look at a little bit more complex example then the first one. Here we are hovering two times. First on the Tutorials then on the Web Design. Below menus are taken from http://line25.com/.


and if we do inspect element for Tutorials it looks as shown below:


The code to work with the above Tutorials menu is: