Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udayanem/7f808f052604b56d319d to your computer and use it in GitHub Desktop.
Save udayanem/7f808f052604b56d319d to your computer and use it in GitHub Desktop.
How to right click on a webelement using webdriver
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 ActBuilderRightClk
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("https://in.yahoo.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement cricket=driver.findElement(By.xpath("//ul[@class='fz-xs']/li[4]"));
Actions action=new Actions(driver);
action.contextClick(cricket).sendKeys(Keys.DOWN).sendKeys(Keys.ENTER).perform(); //short form
// action.moveToElement(cricket).contextClick().sendKeys(Keys.DOWN).sendKeys(Keys.ENTER).perform();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment