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

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?