Selenium WebDriver : Generating Mouse Hover Event On Main Menu To Click On Sub Menu

Selenium WebDriver is totally freeware software testing tool in addition to nosotros tin utilisation it for software spider web application regression purpose. Hovering mouse on principal menu or whatever other chemical component subdivision of spider web page or simulating mouse motility inward webdriver is non real tough task. As y'all know, We tin perform close of actions in addition to operations straight inward webdriver software testing tool and y'all tin VIEW FEW OF THEM ON THIS PAGE. But in that location are also closed to actions which nosotros tin non perform straight inward webdriver in addition to to perform them, nosotros demand to utilisation closed to tricky ways. Generating mouse hover event is 1 of them.

To generate mouse hover upshot inward webdriver software testing tool, We tin use advanced user interactions API constructor "Actions" amongst "moveToElement" method. Bunch of syntax to hover mouse on principal card is every bit bellow. You tin supervene upon xpath of an chemical component subdivision every bit per your requirement inward bellow given syntax.

Actions actions = novel Actions(driver); WebElement moveonmenu = driver.findElement(By.xpath("//div[@id='menu1']/div")); actions.moveToElement(moveonmenu); actions.perform();

Above instance volition solely displace mouse on targeted chemical component subdivision of software spider web application. It volition non perform click operation. To perform click functioning on sub menu, nosotros demand to utilisation click() activity earlier perform() every bit shown inward bellow example.

package junitreportpackage;    import java.io.IOException;  import org.junit.After; import org.junit.Before; import org.junit.Test; 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; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait;   populace course of study Mytesting {  WebDriver driver = novel FirefoxDriver();    @Before  populace void beforetest() {   driver.manage().window().maximize();   driver.get("http://only-testing-blog.blogspot.in/p/mouse-hover.html");  }    @After  populace void aftertest() {   driver.quit();     }    @Test  populace void attempt out () throws InterruptedException, IOException   {     //Generate mouse hover upshot on principal card to click on sub menu   Actions actions = novel Actions(driver);   WebElement moveonmenu = driver.findElement(By.xpath("//div[@id='menu1']/div"));   actions.moveToElement(moveonmenu).moveToElement(driver.findElement(By.xpath("//div[@id='menu1choices']/a"))).click().perform();      WebDriverWait await = novel WebDriverWait(driver, 15);   wait.until(ExpectedConditions.titleContains("Google"));  }     }

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post