To perform mouse hover function over a main menu which has sub elements, for this we have to chain all the actions that we want to achieve in one go.
- In order to perform it, first move on to the main menu element which has sub elements and click on the new option.
- To achieve mouse hover action we use 'Action' API constructor with 'moveToElement' method;
Steps:
1. Launch the site URL(findnerd.com/NerdDigest/)
2. Mouse hover over a main menu(nerd digest)
3. Now find out the hidden element which will only be visible on mouse hover
4. Click on new option or sub menu item(.net)
Sample code:-
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.interactions.Actions;
public class mouseHoverAction{
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("findnerd.com/NerdDigest/");
WebElement mainmenu = driver.findElement(By.xPath(".//*[@id='offshoreindialive']/div[9]/ul/li[10]/a"));
Actions action = new Actions(driver);
action.moveToElement(mainmenu).build().perform();
driver.findElement(By.xpath(".//*[@id='offshoreindialive']/div[9]/ul/li[5]/ul/li[2]/ul/li[1]/a")).click();
}
}
0 Comment(s)