WebDriver: method to get list of frames

7,959 views
Skip to first unread message

cwk

unread,
Aug 23, 2011, 3:49:43 PM8/23/11
to Selenium Users
Hi all,

I am migrating our test framework from selenium rc to webDriver. Is
there a way to get a list of frames on the current page so I can
iterate through it? In rc, I could do something like this:

numFrames = selenium.getXpathCount("//iframe").intValue();

and iterate through numFrames. Is my best option:

numFrames = driver.findElements(By.xpath("//iframe")).intValue();

Or is there a cleaner option, like the getWindowHandles() for frames?

ck

Mark Collin

unread,
Aug 24, 2011, 5:22:07 AM8/24/11
to seleniu...@googlegroups.com
To get a list of all iframes try this:

List <WebElement> framesList = driver.findElements(By.xpath("//iframe"));

You can then iterate through the list and do your tests doing something like
this:

for(WebElement frame:framesList){
//DO something with frame
frame.getText();
}

To get the number of iFrames found you can get the size of the list:

Int listSize = framesList.size();

Hi all,

ck

--
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

cwk

unread,
Aug 24, 2011, 11:50:27 AM8/24/11
to Selenium Users
Thanks Mark.

ck
> For more options, visit this group athttp://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 postmas...@ardescosolutions.com
Reply all
Reply to author
Forward
0 new messages