How to open new window by right clicking on any link & click on any context menu options?

Right Click on webelement & click on second options from context menu. 


        @Test

public static void newwindow() throws InterruptedException, AWTException { 

                driver = new ChromeDriver();

driver.get("https://www.selenium.dev/documentation/webdriver/browser/windows/");

Thread.sleep(3000);

Actions actions = new Actions(driver);

WebElement elementLocator = driver.findElement(By.xpath("//*                                                                                                    [@id=\"main_navbar\"]/ul/li[3]/a/span"));

    // Right click on Element

actions.contextClick(elementLocator).perform();

Thread.sleep(1000);

    //Click on second option from context menu

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_DOWN);

robot.keyPress(KeyEvent.VK_DOWN);

robot.keyPress(KeyEvent.VK_ENTER);

}



Open new window & manage windows

        @Test

        public static void newwindow() throws InterruptedException, AWTException { 

                driver = new ChromeDriver();

driver.get("https://www.selenium.dev/documentation/webdriver/browser/windows/");

Thread.sleep(3000);

driver.switchTo().newWindow(WindowType.WINDOW);

ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());

                driver.switchTo().window(tabs.get(1));

                driver.switchTo().window(tabs.get(0));

}


Comments