Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Drop Down Menu Test Selenium Java Code

Drop Down Menu Test in Java

package com.example.seleniummaster;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class DropDownMenuTest {
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();
    @Before
    public void setUp() throws Exception {
        driver = new FirefoxDriver();
        baseUrl = "http://seleniummaster.com";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testDropDownMenu() throws Exception {
        driver.get(baseUrl + "/sitecontent/seleniummenutest/seleniummenutest.html");

HoverMasteringSeleniumMenu()

         driver.findElement(By.linkText("Selenium IDE")).click();
        driver.navigate().back();

HoverMasteringSeleniumMenu()
        
        driver.findElement(By.linkText("Selenium RC")).click();
        driver.navigate().back();

HoverMasteringSeleniumMenu()
        
        driver.findElement(By.linkText("Selenium Grid")).click();
        driver.navigate().back();

HoverMasteringSeleniumMenu()
        
        driver.findElement(By.linkText("Selenium Server")).click();
        driver.navigate().back();

        driver.findElement(By.linkText("Go Back to the Main Page")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
public void HoverMasteringSeleniumMenu()
{
Locatable hoverItem = (Locatabledriver.findElement(By.xpath("//p[contains(text(),'Mastering Selenium')]"))//locate the Mastering Selenium Menu

Mouse mouse = ((HasInputDevicesdriver).getMouse()//prepare mouse to move

mouse.mouseMove(hoverItem.getCoordinates())//Move the mouse over to the root of the menu
}

    private boolean isElementPresent(By by)

 {
        try {
            driver.findElement(by);
            return true;
        catch (NoSuchElementException e) {
            return false;
        }
    }
}

Code Completed....