Thursday 15 May 2014

How to mouse hover on menu in Selenium webdriver or BDD in Java

How to mouse hover on menu in Selenium webdriver or BDD in Java
In this scenario let assume there are 6 main menu items are there and you have to mouse hover on all menus then  you can use this code.
Hint :- Below you have to change your css selector details as per your website.

Actions action = new Actions(driver);

            int numberOfSubMenu = 6;

            // Hovering over each of the items in the top menu and testing the menu items
            for (int j=2; j<= numberOfSubMenu; j++) {

                WebElement elem = driver.findElement(By.cssSelector(".sf-menunew>li:nth-child(" + j + ")>a:nth-child(1)"));
                action.moveToElement(elem);
                action.perform();
                Thread.sleep(1000);
                 
            }

No comments:

Post a Comment