Automation Using Selenium Webdriver

Monday 12 December 2016

Open a link in a New tab

We use actions objects to open any hyperlink in a new tab. e.g.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;

public class NewTab {
    public static void main(String[] args) {
       WebDriver driver = new FirefoxDriver();
        driver.get("http://www.flipcart.com/");
        driver.manage().window().maximize();
        Actions act = new Actions(driver);
        WebElement link = driver.findElement(By.linkText("Flipkart First"));
        act.moveToElement(link).contextClick().sendKeys("F").perform();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
         driver.close();
   
    }
}

No comments:

Post a Comment