How to get the content of iframe in Java (Selenium)?

147 views
Skip to first unread message

Olfi Oliveira

unread,
Mar 25, 2015, 5:22:41 PM3/25/15
to seleniu...@googlegroups.com

Hello.

I need to get whole content of an iframe using selenium API in java. I want to have access of all content of the incidents in trial version of Remedy.

 

This is the expected result, what I see in the browser:

<div id="WIN_0_304255502" arid="304255502" artype="View" ardbn="z2VF_02"
  arcontainerid="304255802" arpercentwidth="100"
  arpercentheight="100" class="arfid304255502 ardbnz2VF_02"
  ardcf="1" style="top: auto; left: auto; width: 1318px;
  height: 744px; z-index: 1135; min-width: 20px;
  max-width: 32767px; min-height: 20px;
  max-height: 32767px; position: relative; overflow: hidden;
  background-color: transparent;"
  arvfframe="
<iframe style=&quot;top:0px&amp;#59; left:0px&amp;#59; width:1170px&amp;#59;
 
height:744px&amp;#59;
 
background-color: transparent&amp;#59;&quot; name=&quot;VF304255502&quot; frameborder=0
 
scrolling=&quot;no&quot;
 
allowtransparency=&quot;true&quot; arviewbordercolor=&quot;null&quot;title=&quot;z2VF_02&quot;src=&quot;javascript:&amp;quot;&amp;lt;HTML&amp;gt;&amp;lt;/HTML&amp;gt;&amp;quot;&quot;
 
onload=&quot;DVFol&amp;#40;&amp;#41;&quot;>
   
</iframe>
   " arwindowid="0" arstop="1">

   //more elements

For now I try:

WebDriver driver= new HtmlUnitDriver();  
driver
.get(url3);  
saveFile
(driver.getPageSource());  


After run the program, the result that I have it´s not what I expected. Maybe because of iframe that exists.


Result:

<div id="WIN_0_304255502" arid="304255502" artype="View" ardbn="z2VF_02"arcontainerid="304255802"
 
arpercentwidth="100" arpercentheight="100" class="arfid304255502 ardbnz2VF_02"
 
ardcf="1" style="top:0px; left:0px; width:1170px; height:744px;z-index:1135;background-color:transparent;min-width:20px;max-width:32767px;min-height:20px;max-height:32767px;"
 
arvfframe="&lt;iframe style=&quot;top:0px&amp;#59; left:0px&amp;#59; width:1170px&amp;#59;
  height:744px&amp;#59;background-color: transparent&amp;#59;&quot;name=&quot;VF304255502&quot;
  frameborder=0 scrolling=&quot;no&quot; allowtransparency=&quot;true&quot;arviewbordercolor=&quot;null&quot;
  title=&quot;z2VF_02&quot;src=&quot;javascript:&amp;quot;&amp;lt;HTML&amp;gt;&amp;lt;/HTML&amp;gt;&amp;quot;&quot;
  onload=&quot;DVFol&amp;#40;&amp;#41;&quot;>

   &lt;/iframe>
   ">
   
</div>

I also try to access iframe, with the name dynamically (driver.switchTo().frame(driver.findElement(By.name(nameIframe)), but occurs an exception (org.openqa.selenium.NoSuchElementException: Unable to locate element with name: VF304255503).

 

Thanks.


anemuday

unread,
Mar 26, 2015, 2:02:19 AM3/26/15
to seleniu...@googlegroups.com
Olfi,

As per the source code you provided about, i feel the name value is wrong. From source code it is, "VF304255502". Just try with that name.

For detailed explanation of how to switch between frame and page, you can watch my video at below location
Switch between frames and web page

Thanks,
Uday
Selenium WebDriver Videos
Message has been deleted

Olfi Oliveira

unread,
Mar 26, 2015, 7:15:02 AM3/26/15
to seleniu...@googlegroups.com
anemuday,

As that value is dynamic, you above find "VF034255503" but it changes. I made a function that save the name of the iframe on a String, therefore this is not a problem. I use 
driver.switchTo().frame(driver.findElement(By.name(nameIframe))
but the error persists.

What I don´t know is exactly how to access elements inside an iframe that is an attribute of a div.

Thanks.

Olfi Oliveira

unread,
Mar 26, 2015, 10:31:36 AM3/26/15
to seleniu...@googlegroups.com
anemuday,

Your video is very helpfull but your iframes are an element tag. In my case I have iframes as attributes (div element).
If you can help me, please say something.

Thanks.

anemuday

unread,
Mar 27, 2015, 1:55:39 AM3/27/15
to seleniu...@googlegroups.com

The very first thing to do is, you need to switch to iFrame, inorder to work and then find the iFrame object so...
try below:
driver.switchTo().frame(driver.findElement(By.xpath("//div[@id='WIN_0_304255502']/iframe[@name='"+nameIframe+"']")))

First i am identifying Div and then its child iframe
Reply all
Reply to author
Forward
0 new messages