how to access iframe generated by javascript

445 views
Skip to first unread message

carina0110

unread,
Oct 15, 2011, 5:19:06 PM10/15/11
to Selenium Users
(Using Webdriver/Java)

I have an app where you click on one element and an input form popup
frane appears. After many hours trying to find the iframe id, I was
able to get it by right-clicking and "inspecting" the iframe while it
was still loading. At this point, I found that there were 2 iframes
involved. I added the two switchTo() statements (and nothing more) and
I was able to find the input fields.

Now, on the same frame, clicking a menu item causes a new frame to
appear in the same popup window. I tried to do the same to locate the
iframes ("inspecting" while loading, before any element is visible)
and I could see the two frames where the first one is the same as the
first one the previous popup. So added those two statements using the
new frame ids, but it's not working! What's the problem?

If I have to use the javascriptexecutor, could someone tell me how and
where in the series of events do I put it?

Thanks

Kevin Patrick

unread,
Oct 17, 2011, 6:11:00 PM10/17/11
to Selenium Users
I'm not sure if this will help, but I was having a problem locating an
iframe as well. In my case, I'm using IE only because it is the only
browser this particular web site runs on. I knew I needed to access
the innerHTML but could not figure out the frame. I needed to select
the correct frame. Here's what I did:
selenium.selectFrame("index=0"); //select the frame that contains
the benefit information
String html =
selenium.getEval("window.document.body.getElementsByTagName('iframe')
[0].contentWindow.document.body.innerHTML");
Before I resolved this problem I was making the getEval call but I was
getting information contained in the parent. I believe that was the
case because I was in the parent:
selenium.selectFrame("relative=parent");
And if you are currently in the correct from you may want to try point
to frame[1] like this:
String html =
selenium.getEval("window.document.body.getElementsByTagName('iframe')
[1].contentWindow.document.body.innerHTML");

Mark Collin

unread,
Oct 18, 2011, 4:08:32 AM10/18/11
to seleniu...@googlegroups.com
That's a lot of work when you could just do:

WebElement myIFrame = driver.findElement(By.xpath("(//iframe)[1]"));
driver.switchTo().frame(myIFrame);

First line will select the first instance of iframe on the site and the
second line will switch to it.

That being said, I would suggest it's time to swot up on your HTML so that
you can get to the point where you can read the page source and work out
what is going on without needing tools like firebug, your productivity will
drastically increase.

--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Reply all
Reply to author
Forward
0 new messages