Frame - W4D1-1
~30 mins
Frame
package week4.day1;
import java.time.Duration;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.github.bonigarcia.wdm.WebDriverManager;
public class LearnFrame {
public static void main(String[] args) {
// Steps to launch driver, app,maximize, set timeout
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://dev68594.service-now.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
// I found a frame, hence switch to it !!
driver.switchTo().frame("gsft_main");
driver.findElement(By.id("user_name")).sendKeys("admin");
driver.findElement(By.id("user_password")).sendKeys("India@123");
driver.findElement(By.id("sysverb_login")).click();
}
}
package week4.day1;
import java.time.Duration;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.github.bonigarcia.wdm.WebDriverManager;
public class LearnJQuery {
public static void main(String[] args) {
// Steps to launch driver, app,maximize, set timeout
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://jqueryui.com/draggable/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
// I found a frame, hence switch to it !!
driver.switchTo().frame(0); // using the index
//WebElement frameElement = driver.findElement(By.className("demo-frame"));
//driver.switchTo().frame(frameElement);
// index (int), id or name (String), find the webelement for the frame
// find out if the element draggable exist !!
boolean displayed = driver.findElement(By.id("draggable")).isDisplayed();
System.out.println("Displayed :"+displayed);
// Come out of the frame
driver.switchTo().defaultContent();
// Will it work?
driver.findElement(By.linkText("Demos")).click();
}
}
package week4.day1;
import java.time.Duration;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import io.github.bonigarcia.wdm.WebDriverManager;
public class W3Schools {
public static void main(String[] args) {
// Steps to launch driver, app,maximize, set timeout
WebDriverManager.chromedriver().setup();
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
// Switch to the frame
driver.switchTo().frame("iframeResult");
// Click on the Try It
driver.findElement(By.xpath("//button[text()='Try it']")).click();
// Switch to the alert and accept
driver.switchTo().alert().accept();
// Confirm the accept works !!
String text = driver.findElement(By.id("demo")).getText();
System.out.println(text);
}
}