Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Right Click and Choose an Option Using Selenium WebDriver

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.76k
    Comment on it

    Here, we discuss that how to right click on a link or button and choose any option from the list using Selenium WebDriver. In this, Actions Class helps to right click on any element.

     

    Also, we need to import:

     

    'import org.openqa.selenium.interactions.Actions'

     

     

    Steps to be automated:

     

    • Launch the browser
    • Open your site
    • Find the element on which you want to perform Right click action
    • Open that link in new tab

     

     

    WebDriver Code goes as below:

     

    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 RightClick {
    
    	public static void main(String[] args) {
    		
            WebDriver driver = new FirefoxDriver();
    		
            driver.get("http://google.com");
            
            
    		driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
    		driver.manage().window().maximize();
    		
    		
    		WebElement gmail = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a"));
    		
    		Actions action1 = new Actions(driver);
    		action1.contextClick(gmail).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();;
    
    
    	}
    
    }
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: