How to perform right click using Selenium WebDriver?
package pkg_selenium;
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 DoubleClick {
public static WebDriver driver;
public static void main(String args[]) throws Exception{
// Initialize WebDriver
driver = new FirefoxDriver();
// Wait For Page To Load
driver.manage().timeouts().pageLoadTimeout(60,TimeUnit.SECONDS);
// Go to google Page
driver.get("http://www.google.co.in/");
// Maximize Window
driver.manage().window().maximize();
WebElement hindiLanguage = driver.findElement(By.xpath("//font[@id='addlang']/a[1]"));
// Initialize Actions class object
Actions builder = new Actions(driver);
// Perform Right Click on 'हिन्दी' language and Open Google in 'हिन्दी' language in a different Window
builder.contextClick(hindiLanguage).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();
Thread.sleep(15000L);
// Close Driver
driver.quit();
}
}
Comments
Post a Comment