Frames and Windows
Frames and Windows
Frames and Windows
Single frame
:
package Frames;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
System.setProperty("webdriver.chrome.
driver","D://chromedriver.exe");
ChromeDriver d=new
ChromeDriver();
d.get("https://demoqa.com/frames");
d.manage().window().maximize();
System.out.println(d.getTitle());
System.out.println(
d.getCurrentUrl());
d.switchTo().frame("frame1");
WebElement
text=d.findElement(By.id("sampleHeadi
ng"));
System.out.println(text.getText());
System.out.println(d.getTitle());
System.out.println(d.getCurrentUrl())
;
d.switchTo().frame("iframe1");
d.findElement(By.xpath("//
button[@id='u_5_6']")).click();
WebElement
text=d.findElement(By.id("processing"
));
System.out.println(text.getText());
Multiple frames:
package Frames;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
System.setProperty("webdriver.chrome.
driver","D://chromedriver.exe");
ChromeDriver d=new
ChromeDriver();
d.get("https://www.dezlearn.com/neste
d-iframes-example/");
d.manage().window().maximize();
System.out.println(d.getTitle());
System.out.println(d.getCurrentUrl())
;
System.out.println("First Frame");
d.switchTo().frame("parent_iframe");
d.findElement(By.id("u_5_5")).click()
;
WebElement
t1=d.findElement(By.id("processing"))
;
System.out.println(t1.getText());
Thread.sleep(2000);
System.out.println("second Frame");
d.switchTo().frame("iframe1");
d.findElement(By.id("u_5_6")).click()
;
WebElement
t2=d.findElement(By.id("processing"))
;
System.out.println(t2.getText());
System.out.println("switching to
frist frames");
d.switchTo().defaultContent();
d.switchTo().frame("parent_iframe");
WebElement
t3=d.findElement(By.id("processing"))
;
System.out.println(t3.getText());
Obj.getwindowHandle();//parent id
Get Windowhandles : get the multiple window ids
Obj.getwindowhandles();//ids of parent
as well as child ids”
MULTIPLE TABS:
package Windows;
import java.util.Set;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
public class New_Tab {
System.setProperty("webdriver.chrome.
driver","D://chromedriver.exe");
ChromeDriver d=new ChromeDriver();
d.get(baseurl);
d.manage().window().maximize();
String p1=d.getWindowHandle();
System.out.println(p1);//parent id
d.findElement(By.id("tabButton")).cli
ck();
Set<String>p2=d.getWindowHandles();
System.out.println(p2);//parent id as
well as child id
System.out.println(p2.size());
System.out.println(text.getText());
}
d.switchTo().window(p1);
}
Multiple windows :
package Windows;
import java.util.Set;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.chrome.ChromeDriv
er;
System.setProperty("webdriver.chrome.
driver","D://chromedriver.exe");
ChromeDriver d=new ChromeDriver();
d.get(baseurl);
d.manage().window().maximize();
String p1=d.getWindowHandle();
System.out.println(p1);//parent id
d.findElement(By.id("tabButton")).cli
ck();
Set<String>p2=d.getWindowHandles();
System.out.println(p2);//parent id as
well as child id
System.out.println(p2.size());
System.out.println(text.getText());
d.close();
}
}