Monday 10 August 2015

Right click on the mouse.

package test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
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;
import org.testng.annotations.Test;

public class RightClick {

    @Test
    public void rightClicktest(){
        WebDriver driver = new FirefoxDriver();
        driver.navigate().to("http://www.google.com");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
       
        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("lst-ib")));
       
        WebElement element = driver.findElement(By.id("lst-ib"));
        element.sendKeys("");
        element.click();
       
        Actions actObj = new Actions(driver);
        actObj.contextClick(element).sendKeys(Keys.ARROW_DOWN).
            sendKeys(Keys.ARROW_DOWN).
            sendKeys(Keys.ARROW_DOWN).
            sendKeys(Keys.ARROW_DOWN).
            sendKeys(Keys.RETURN).perform();

    }
}

No comments:

Post a Comment