-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample11.java
More file actions
47 lines (36 loc) · 1.46 KB
/
Example11.java
File metadata and controls
47 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.SeleniumTestingSamples.Examples;
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
//Frame handling EXAMPLE
public class Example11{
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
String Url = "https://www.leafground.com/frame.xhtml";
driver.get(Url);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10000));
driver.manage().window().maximize();
//Find total number of Frames
driver.switchTo().defaultContent();
List <WebElement> totalFrames = driver.findElements(By.tagName("iframe"));
int size = totalFrames.size();
System.out.println("Total no of Frames:" + size);
//Access Frames
driver.switchTo().frame(0);
WebElement button1 = driver.findElement(By.id("Click"));
button1.click();
String text = driver.findElement(By.id("Click")).getText();
System.out.println(text);
//Access Nested frames
driver.switchTo().defaultContent();//Switch back to main web page
driver.switchTo().frame(2);
driver.switchTo().frame("frame2");
WebElement button2 = driver.findElement(By.xpath("//*[@id=\"Click\"]"));
String text1 = button2.getText();
System.out.println(text1);
driver.switchTo().defaultContent();//Switch back to main web page
}
}