Q:

How to open a link in the adjacent window or tab using actions class (Context click on element->sendkeys ArrowDown ->sendkeys Enter)

I want to open a link of an application in a new window. Using actions class is opening the link in same window i am currently on.
I have tried using Actions class with the below code on both chrome driver and firefox driver with multiple applications but none worked.
System.setProperty("webdriver.gecko.driver", "D:\\MySpace\\AmozonEcomm\\Dependencies\\geckodriverv21.exe");
WebDriver driver = new FirefoxDriver(); //Creating an instance of Chrome driver
driver.manage().window().maximize();
driver.get("http://automate-apps.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

Actions action = new Actions(driver);
action.contextClick(driver.findElement(By.partialLinkText("Selenium Questions"))).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();

My expectation is that the link should get opened in a new window as i am trying to select the "Open link in new window" option after context click. But evrytime the link is getting opened in same window.

A:

Here are two options for opening a link in a new window (not tab).
WebElement el = driver.findElement(By.partialLinkText("Selenium Questions"));
Actions action = new Actions(driver);

contextClick - contextClick() can be capricious, in some environments it simply refuses to achieve the same result as it does in others.
Still if you want to try with it, send the "w" key - that's the shortcut for "Open In New Window":
action.contextClick(el).perform();
action.sendKeys("w").perform();  // in two steps

Shift-click - the shortcut for new window is shift-click, as opposed to ctrl-click for new tab. This approach is having higher repeatability rate vs contextClick() - as long as the browser supports it. 
action.keyDown(Keys.SHIFT).click(el).keyUp(Keys.SHIFT).build().perform();

