My goal is to open a link in a new tab and switch to that tab using Selenium in Java with a Firefox browser. I have been successful in opening the link in the same window but am struggling to incorporate sendKeys for my desired action.
WebElement we = driver.findElement(By.xpath("//*[@id='btn']"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", we);
The above code worked perfectly for me, however, I am now attempting to use sendKeys as shown below, which is not producing the desired result:
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("keyDown(Keys.CONTROL)
.keyDown(Keys.SHIFT)
.click(arguments[0])
.keyUp(Keys.CONTROL)
.keyUp(Keys.SHIFT);", we);
Any suggestions or advice? I am struggling to find the correct syntax for sending keys through JavascriptExecutor. I have tried similar solutions using Actions without success as well.