How to perform mouse right click event in Selenium WebDriver using java?



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;

public class Mouserightclick {

    public static void main(String[] args) {

        // WebDriver reference but Firefox object
        WebDriver dr = new FirefoxDriver();
        //Maximize browser window       
        dr.manage().window().maximize();
        //Go to URL      
        dr.get("http://www.google.com");
        //Set  timeout      
        dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //action object
        Actions action = new Actions(dr);
         //perform mouse right click action
        action.contextClick(dr.findElement(By.linkText("Gmail"))).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();      
        //close firefox browser  
        dr.close();
    }

}


No comments:

Post a Comment