How to find iframes and their attributes with out seeing html code:
===================================================
package blog;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class FrameAttributesDemo {
WebDriver driver;
String expectedTitle = "jQuery UI";
@BeforeSuite
public void openBrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@AfterSuite
public void closeBrowser() {
if (driver!=null) {
driver.quit();
}
}
@Test
public void testScript() {
driver.get("https://www.jqueryui.com");
String actualTitle = driver.getTitle();
if (actualTitle.equalsIgnoreCase(expectedTitle))
{
driver.findElement(By.linkText("Autocomplete")).click();
}
java.util.List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
for (WebElement webElement : iframes) {
String name = webElement.getAttribute("name");
String id = webElement.getAttribute("id");
String clas = webElement.getAttribute("class");
System.out.println("iframe name is : " +name);
System.out.println("iframe id is : " +id);
System.out.println("iframe clas is : " +clas);
}
}
}
===================================================
package blog;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class FrameAttributesDemo {
WebDriver driver;
String expectedTitle = "jQuery UI";
@BeforeSuite
public void openBrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
}
@AfterSuite
public void closeBrowser() {
if (driver!=null) {
driver.quit();
}
}
@Test
public void testScript() {
driver.get("https://www.jqueryui.com");
String actualTitle = driver.getTitle();
if (actualTitle.equalsIgnoreCase(expectedTitle))
{
driver.findElement(By.linkText("Autocomplete")).click();
}
java.util.List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
for (WebElement webElement : iframes) {
String name = webElement.getAttribute("name");
String id = webElement.getAttribute("id");
String clas = webElement.getAttribute("class");
System.out.println("iframe name is : " +name);
System.out.println("iframe id is : " +id);
System.out.println("iframe clas is : " +clas);
}
}
}
No comments:
Post a Comment