List<WebElement> frameset = driver.findElements(By.tagName("frame"));
if(frameset.size()>0) {
for (WebElement framename : frameset){
System.out.println("frameid: " + framename.getAttribute("name"));
}
}
else System.out.println("can not find any frame in HTML");
Notice when you set the frame index, it starts with 0 for the first frame:
driver.switchTo().frame(0);
2> Switch to different Windows:
Set<string> handlers = driver.getWindowHandles();
if (driver.getWindowHandles().size()>= 1){
for(String handler : handlers){
driver.switchTo().window(handler);
if (driver.getCurrentUrl().contains("Popup")){
System.out.println("Get focus on Popup window");
break;
}
}
}
else System.out.println("No windows founded!");
Writing a common function based you own app for switching will be more helpful for your Code Clean!
Than q
ReplyDeleteThis is helpful.. Thanks
ReplyDeleteThank you!
ReplyDeleteExcellent thanks a million
ReplyDeleteReally nice:) Thanks from Poland:)
ReplyDeleteThis helped me lot. Thanks
ReplyDeleteGreat Job!
ReplyDelete/*multiple iframes*/
ReplyDeleteWebDriver driver = new FirefoxDriver();
driver.get("http://timesofindia.indiatimes.com/");
//will not work in FF
//driver.switchTo().frame("mailroifrm12");
WebElement ifr = driver.findElement(By.xpath("//iframe[@id='mailroifrm12']"));
driver.switchTo().frame(ifr);
Thread.sleep(3000L);
driver.findElement(By.id("mathuserans2")).sendKeys("8");
Thank you!
ReplyDelete