Moving between frames...
Consider an application where the contents are in different frames
and need to fetch data from a frame
In the above example consider that after selecting an item in frame 2 the contents are displayed in frame 3 now need to read the data in frame 3
public void default_frame(){
try{
driver.switchTo().defaultContent();
frames(Frame1,fmset);
}catch(Exception e){
e.printStackTrace();
}
}
In the above code first we are moving to default frame by switching to default content
public void frames(final String x, final String y){
try{
driver.switchTo().frame(x);
System.out.println(":::::::::: Frame 1 is switched " + x);
driver.findElement(By.tagName(y));
System.out.println(":::::::::: Frameset value " + driver.findElement(By.tagName(y)) + "::::");
}catch(Exception e){
e.printStackTrace();
}
}
In the above code after moving to frames, now need to go the frames which we require
public void Frame2(final String x){
try{
System.out.println(":::::::::: Entering into Left Frame");
driver.switchTo().frame(x);
System.out.println(":::::::::: Switching to Left frame==>" +x);
java.util.List<WebElement> list = driver.findElements(By.name(xxxxxxxxxx));
System.out.println("Left frame items: " +list.size());
for(WebElement sug:list ) {
int i =1;
System.out.println("Items of left frame"+i+sug.getText());
i++;
}
}catch(Exception e){
e.printStackTrace();
}
In the above code after moving to frames now to click on content in frame 2 the above code could be helpful
and need to fetch data from a frame
FRAME-1
|
|
FRAME-2
|
FRAME-3
|
In the above example consider that after selecting an item in frame 2 the contents are displayed in frame 3 now need to read the data in frame 3
public void default_frame(){
try{
driver.switchTo().defaultContent();
frames(Frame1,fmset);
}catch(Exception e){
e.printStackTrace();
}
}
In the above code first we are moving to default frame by switching to default content
public void frames(final String x, final String y){
try{
driver.switchTo().frame(x);
System.out.println(":::::::::: Frame 1 is switched " + x);
driver.findElement(By.tagName(y));
System.out.println(":::::::::: Frameset value " + driver.findElement(By.tagName(y)) + "::::");
}catch(Exception e){
e.printStackTrace();
}
}
In the above code after moving to frames, now need to go the frames which we require
public void Frame2(final String x){
try{
System.out.println(":::::::::: Entering into Left Frame");
driver.switchTo().frame(x);
System.out.println(":::::::::: Switching to Left frame==>" +x);
java.util.List<WebElement> list = driver.findElements(By.name(xxxxxxxxxx));
System.out.println("Left frame items: " +list.size());
for(WebElement sug:list ) {
int i =1;
System.out.println("Items of left frame"+i+sug.getText());
i++;
}
}catch(Exception e){
e.printStackTrace();
}
In the above code after moving to frames now to click on content in frame 2 the above code could be helpful
Comments