package com.seleniumWebdriver;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class BrowserNewTab extends SuperTestNG {
String mainWindow;
String childWindow;
String gc;
String URL = "http://only-testing-blog.blogspot.in/2013/09/testing.html";
public void scrollingToBottomofAPage() {
driver.navigate().to(URL);
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
}
@Test
public void handleSameBrowserNewTab() throws InterruptedException {
try {
System.out.println("handleSameBrowserNewTab() start");
driver.get(URL);
scrollingToBottomofAPage();
driver.findElement(By.xpath("//a[1]/b/span")).click();
System.out.println("-------After clicking on Visit MyTest Page Link -----");
Set<String> windowHandles = driver.getWindowHandles();
Iterator<String> it = windowHandles.iterator();
mainWindow = it.next();
childWindow = it.next();
System.out.println("No. of pages windowHandles:" + windowHandles.size());
System.out.println("No. of pages on Main Page: " + mainWindow);
System.out.println("No. of pages on Child Page: " + childWindow);
driver.switchTo().window(childWindow);
driver.close();
driver.switchTo().window(mainWindow);
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.testng.annotations.Test;
/**
* @Blog Name : Selenium Code Example
* @author Deepak Gupta
* @Created Date 4-08-2017
*
*/
public class BrowserNewTab extends SuperTestNG {
String mainWindow;
String childWindow;
String gc;
String URL = "http://only-testing-blog.blogspot.in/2013/09/testing.html";
public void scrollingToBottomofAPage() {
driver.navigate().to(URL);
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
}
@Test
public void handleSameBrowserNewTab() throws InterruptedException {
try {
System.out.println("handleSameBrowserNewTab() start");
driver.get(URL);
scrollingToBottomofAPage();
driver.findElement(By.xpath("//a[1]/b/span")).click();
System.out.println("-------After clicking on Visit MyTest Page Link -----");
Set<String> windowHandles = driver.getWindowHandles();
Iterator<String> it = windowHandles.iterator();
mainWindow = it.next();
childWindow = it.next();
System.out.println("No. of pages windowHandles:" + windowHandles.size());
System.out.println("No. of pages on Main Page: " + mainWindow);
System.out.println("No. of pages on Child Page: " + childWindow);
driver.switchTo().window(childWindow);
driver.close();
driver.switchTo().window(mainWindow);
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment