Context menu / right click with selenium

There are certain scenarios where we want to perform context right click on any object using selenium.
one of the example, some website supports context menu "Save link as" option to download any items like songs, files etc...

Let's see the implementation





 package testPkg;
 
 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 RightClick {
 
  public static void main(String[] args) {
 WebDriver driver =  new FirefoxDriver();
 driver.get("http://www.qavalidation.com/p/demo.html");
 WebElement lnk_sel = driver.findElement(By.linkText("Selenium Tutorial!"));
 
 Actions action= new Actions(driver);
 action.contextClick(lnk_sel).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
  
 }
}

No comments:

Post a Comment