import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Openandclosetabhandler {
public static void main(String[] a) throws InterruptedException {
// Initialize driver
WebDriver driver = new FirefoxDriver();
//Maximize browser window
driver.manage().window().maximize();
//Go to URL
driver.get("http://www.google.com");
//Set timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Open new tab
driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND + "t");
//Go to URL
driver.get("http://www.yahoo.com/");
//Set new tab timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Do some operation
driver.findElement(By.partialLinkText("Sign in")).click();
Thread.sleep(2000);
// Switch first tab
driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND + "w");
driver.switchTo().defaultContent();
Thread.sleep(2000);
// Operation
driver.findElement(By.partialLinkText("Gmail")).click();
Thread.sleep(2000);
// Browser close
driver.close();
}
}
How can open and close browser tabs in selenium Webdriver on Mac using java.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment