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

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

What is data driven testing?

API Automation Testing Script to check Response

How to handle frame window in selenium?

How to work with mouse hover menu in selenium?

How does Selenium Webdriver handle SSL certificate in Chrome?