Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Showing posts with label Test menus/Submenus using action class. Show all posts
Showing posts with label Test menus/Submenus using action class. Show all posts

Monday, 22 December 2014

How to test menus/Submenus using action class(Mouse hovering in Webdriver)

Many of the times we need to test Menus and Submenus in Selenium.
Selenium WebDriver has Advanced User Interactions API (Actions class) to perform this kind of advanced user interactions for rich applications.We can use Actions class and It different methods like moveToElement, dragAndDrop, clickAndHold.These all actions are called Mouse Hover action in Selenium Webdriver.
So Where to use these mouse hovering action.

Whenever you are Testing Menus/Submenus of a Website and you find some hidden elements/getting exception like Element is not currently visible and so may not be interacted with
At that time you need to perform mouse hovering
How to find that Webelement is Hidden.By this link you can find out element is hidden o not.
How to do Mouse Hover in SeleniumWebDriver
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class TestingSubmenu {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.neogenomics.com/solutions-overview.htm");
    Boolean submenu =     driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0_m2']/span")).isDisplayed();
       System.out.println(submenu);
//If this method returns true then it is visible element and if returns False then it is hidden element.
     WebElement Menu = driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0']/img"));
       WebElement Submenu = driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0_m2']/span"));      
       if(submenu==false){
      //Use of Action class  
       Actions builder = new Actions(driver);
       builder.moveToElement(Menu).build().perform();
//Move your mouse on Testing Services 
       driver.findElement(By.xpath("//*[@id='ctl00_Header1_HorizontalNavigation1_Menu_m0_m2']/span")).click();
       Submenu.click();
//Click on Testspotlight 
       }    
       }

}

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: