Tuesday, 18 November 2014

how to find dynamic elements in selenium

how to find dynamic elements in selenium

//how to find dynamic elements in selenium
package com.snapdeal;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Dynamicelments {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get(“http://timesofindia.indiatimes.com/home”);
List<WebElement> frame = driver.findElements(By.tagName(“iframe”));
System.out.println(frame.size());
for (int i = 0; i < frame.size(); i++) {
System.out.println(frame.get(i).getAttribute(“id”));
driver.close();
}
}
}

/*
Output is
Run for first time o/p is
2
a9982952-2553-8973-fe5d-294b67e69809
Run for second time o/p is
2
902f94fd-3c30-c01d-e35a-269a7a300ef7
Run for third time o/p is
2
32bf57b6-5096-bc5c-df4a-b582df5ee5dd
*/

No comments:

Post a Comment