Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 2 - Switching focus to a frame that has no name/id

So right now I'm trying to figure out how I can switch focus to a frame in Selenium 2 when the frame has no name or id? For a named frame I do:

driver.SwitchTo().Frame(FrameName);

but what is there is no name? Has anyone had experience with this?

like image 749
James Avatar asked Aug 23 '10 16:08

James


Video Answer


2 Answers

driver.switchTo.frame() is overloaded to accept a frame name or an integer. This int is a 0 based index of the frames available. The first frame would be 0, the second 1 and so on.

I've just run a really quick test using the java binding and Firefox against this HTML page.

<html>
<frameset rows="50%,50%">
    <frame src="frame_a.htm" />
    <frame src="frame_b.htm" />
</frameset>
</html>

I'm successfully able to use driver.switchTo().frame(0); to refer to frame a and driver.switchTo().frame(1); to access frame b.

like image 101
pnewhook Avatar answered Sep 30 '22 18:09

pnewhook


You can use the index of the frame. Since you don't have name and id for the frame, driver.switchTo().frame(int frameIndex)

like image 30
nilesh Avatar answered Sep 30 '22 18:09

nilesh