- bhaskarvphani
- Posts : 1
Join date : 2012-03-27
Switching between nested iframes within a frame
Sun Apr 01, 2012 3:06 am
Please help me in resolving the following issue.
Hierarchy of Frameset, frames and iframes in a single web page
Frameset id=”mainframeset”….
frame id=”usersession”…
Frameset id=”lowerframeset”..
Frame id=”Nav”
Frameset =”main pane”…
Frame id=”Work”…
Iframe1 :(each Iframe have attributes frameborder="0",allowtransparency="true",tabindex="0",src="",title="Rich text editor, work_135(only change is this id for each iframe), press ALT 0 for help.",style="width:100%;height:100%"
Iframe2: (each Iframe have attributes frameborder="0", allowtransparency="true",tabindex="0",src="",title="Rich text editor, work_140(only change is this id for each iframe), press ALT 0 for help.",style="width:100%;height:100%"
Iframe3:
Iframe4:
Code I have is :
driver.switchTo().defaultContent();
driver.switchTo().frame("work");
System.out.println(" Switched to Work ");
List Element = driver.findElements(By.xpath("//iframe"));
System.out.println("No of Iframes are :"+ Element.size());
System.out.println(driver.switchTo().frame(Element.get(0)));
driver.findElement(By.xpath("//*[@id='ck_article_title']")).click();
driver.findElement(By.xpath("//*[@id='ck_article_title']/p[1]")).sendKeys("Ifram 1 ");
System.out.println(driver.switchTo().frame(Element.get(1)));
driver.findElement(By.xpath("//*[@id='ck_article_standfirst']")).click();
driver.findElement(By.xpath("//*[@id='ck_article_standfirst']/p[1]")).sendKeys("I frame 2 ");
Error while running the above code:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element belongs to a different frame than the current one - switch to its containing frame to use it
Problem:
a) The above code enters the text in iframe 1 but gives above error when trying to identify iframe2 within frame "work"
Please help me to identify each iframes sequentially and enter required text in it.
Hierarchy of Frameset, frames and iframes in a single web page
Frameset id=”mainframeset”….
frame id=”usersession”…
Frameset id=”lowerframeset”..
Frame id=”Nav”
Frameset =”main pane”…
Frame id=”Work”…
Iframe1 :(each Iframe have attributes frameborder="0",allowtransparency="true",tabindex="0",src="",title="Rich text editor, work_135(only change is this id for each iframe), press ALT 0 for help.",style="width:100%;height:100%"
Iframe2: (each Iframe have attributes frameborder="0", allowtransparency="true",tabindex="0",src="",title="Rich text editor, work_140(only change is this id for each iframe), press ALT 0 for help.",style="width:100%;height:100%"
Iframe3:
Iframe4:
Code I have is :
driver.switchTo().defaultContent();
driver.switchTo().frame("work");
System.out.println(" Switched to Work ");
List
System.out.println("No of Iframes are :"+ Element.size());
System.out.println(driver.switchTo().frame(Element.get(0)));
driver.findElement(By.xpath("//*[@id='ck_article_title']")).click();
driver.findElement(By.xpath("//*[@id='ck_article_title']/p[1]")).sendKeys("Ifram 1 ");
System.out.println(driver.switchTo().frame(Element.get(1)));
driver.findElement(By.xpath("//*[@id='ck_article_standfirst']")).click();
driver.findElement(By.xpath("//*[@id='ck_article_standfirst']/p[1]")).sendKeys("I frame 2 ");
Error while running the above code:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element belongs to a different frame than the current one - switch to its containing frame to use it
Problem:
a) The above code enters the text in iframe 1 but gives above error when trying to identify iframe2 within frame "work"
Please help me to identify each iframes sequentially and enter required text in it.
Permissions in this forum:
You cannot reply to topics in this forum