Session 30 – Selenium with Java | Handling Frames/iFram… — Transcript

Learn how to handle frames, iframes, and nested iframes in Selenium with Java, including switching commands and element interaction techniques.

Key Takeaways

  • Frames and iframes are different but handled similarly in Selenium.
  • Switching driver context to the frame is mandatory to interact with its elements.
  • Frames can be identified by ID, name, or WebElement for switching.
  • Always switch back to the main page after frame interaction.
  • Nested frames require multiple switches to access inner elements.

Summary

  • Explanation of the difference between frames and iframes in web applications.
  • Frames and iframes embed one web page inside another, often from external sources.
  • Selenium requires switching the driver context to the frame or iframe to interact with elements inside it.
  • Driver cannot directly interact with elements inside frames without switching context.
  • Frames can have tag names like frame, iframe, or form.
  • Methods to switch to frames include using frame ID, name, or WebElement.
  • After interacting with elements inside a frame, the driver must switch back to the main page.
  • Nested frames and iframes require sequential switching to access inner elements.
  • Common exceptions like NoSuchElementException occur if the driver does not switch to the correct frame.
  • Using tools like Selector Hub can help identify frame XPaths and element locators.

Full Transcript — Download SRT & Markdown

00:04
Speaker A
So in the last session, we have seen how to handle alerts by using the switching command driver.switchTo().alert(). Now, today we'll see how to handle frames, or we can also call them as iframes.
00:28
Speaker A
and what is I frame and what is the difference so most of the people will think both are exactly the same uh but actually they're not exact same but the way of handling the frames and I frames is
00:42
Speaker A
Okay, so first of all, let us see what is a frame and what is an iframe, and what is the difference.
01:02
Speaker A
second okay and let's say you have some page like this and inside the page you will have uh different type of elements and sometimes what will do is same type of elements we will keep in uh different place or we can separate them as a group let us say here we will keep some elements
01:27
Speaker A
So most people will think both are exactly the same, but actually, they're not exactly the same. However, the way of handling the frames and iframes is exactly the same in Selenium, especially.
01:49
Speaker A
come to web applications uh this particular content is there in the frame right so that is actually a different web page okay different web page and that particular web page we are embedding into the actual web page so this is the actual web page that we are showing or that we
02:08
Speaker A
Okay, so what is a frame and what is an iframe, especially when you are working with desktop applications, not web applications? Especially when you're working with desktop applications, let us say you have one small application. Just a second.
02:30
Speaker A
some web page we are displaying in another web page and we are embedding this page into another web page and when you embedded this page into another web page the tag name of this Frame is I frame or frame or sometimes it will be form so these are the different tag names you can see for
02:53
Speaker A
Okay, and let's say you have some page like this, and inside the page, you will have different types of elements. Sometimes what we do is, same type of elements we will keep in different places, or we can separate them as a group. Let us say here we will keep some elements,
03:07
Speaker A
those elements okay so for example let's say this is my web page this is my actual main web page and here this is another page and this is a embedded page which is coming from external source so this
03:23
Speaker A
and here we'll keep other elements, and here I'll keep other elements. So we will divide the elements into different groups, and those elements we'll keep in separate sections, which is called frames.
03:44
Speaker A
cannot directly interact so why because our driver is always focused on the page level page the entire page but this page contains this particular frame right so this Frame contains some more elements so our driver cannot go from page to this particular frame directly so we cannot directly
04:07
Speaker A
Okay, these are all frames, especially in desktop applications. Okay, and when you come to web applications, this particular content is there in the frame, right?
04:27
Speaker A
switched then we can interact with the elements as usual just like a normal way okay and once you have done this again we have to go back to the main page because our driver still focused only on the frame once you switched it our driver is there in only in the frame once your job is done here
04:46
Speaker A
So that is actually a different web page, okay, a different web page, and that particular web page we are embedding into the actual web page. So this is the actual web page that we are showing or that we are displaying in the current web page.
05:04
Speaker A
command but what is the parameter we have to pass here we can pass ID of the frame or we can pass name of the frame sometimes ID name Properties or attributes we can directly find in HTML so we can
05:18
Speaker A
Let's say this is another web page, and this is another web page, and these pages have different URLs also, and we will showcase all the pages in one single page. That is an external page again, and this is called iframe.
05:35
Speaker A
these are the three different options are there three different flavors we can directly pass ID if there is an ID here with the double codes or if the name is available for the frame directly you can pass name and if ID name is also not available then we can find this entire frame as a one single
05:52
Speaker A
This is called iframe. That means some web page we are displaying in another web page, and we are embedding this page into another web page.
06:25
Speaker A
once our driver is enter into the frame how we can again come back to the page so for every option so we have different methods we will see one by one so first let us start with uh one
06:39
Speaker A
And when you embed this page into another web page, the tag name of this frame is iframe or frame, or sometimes it will be form. So these are the different tag names you can see for the frame. It can be iframe, or it can be frame, or it can be form.
08:12
Speaker A
page actually that page is got uh changed okay now let us take uh some other application so if I look at here uh there are different uh frames are there in this page this is all one single page this will give you the entire page and here this is uh frame one
08:38
Speaker A
Okay, so if the elements are present inside the iframe or inside the frame or inside the form, the problem is we cannot directly inspect those elements.
08:56
Speaker A
can see this is I frame inside frame so this this is actually another frame in the frame three this is another form okay so this is a page so now let's see how can we handle this so I want to
09:13
Speaker A
Okay, so for example, let's say this is my web page, this is my actual main web page, and here this is another page, and this is an embedded page which is coming from an external source.
09:30
Speaker A
and this is the HTML you can see here frame set frame set contains a number of frames and if you expand here this is a frame and again the frame set contains another frame set these are the two
09:44
Speaker A
So this is the actual web page we are displaying the same page here, and which contains some elements.
10:05
Speaker A
or I frame sometimes you can say I frame as a dag okay so now let's see how to interact with this element from the frame one and go back to your Eclipse create new class sorry new package day 30 andle
10:42
Speaker A
Okay, and if this page is an external page, we can access everything directly, but once you embed this page or embed this into this page as a form, okay, or this is a frame, and these elements we cannot directly interact.
11:22
Speaker A
free so let us directly inspect this element and we'll see directly how can we interact with this and what kind of exception you are getting so basically this is input tag okay and uh this is a uh X path of this element get this x path and try to find that element driver dot find element
11:49
Speaker A
So why? Because our driver is always focused on the page level, the entire page, but this page contains this particular frame, right?
12:23
Speaker A
element exception so why it is saying no such element exception because this element is part of the frame so that is the reason it is unable to find the element with this locator right so if I go back to the selector Hub the selector Hub also will very much help you here it is clearly saying
12:44
Speaker A
So this frame contains some more elements, so our driver cannot go from page to this particular frame directly. So we cannot directly inspect these elements. We cannot directly perform any actions on these elements.
13:07
Speaker A
to access it through automation right so it is clearly saying that so also another advantage of this is it is also giving the x paath of that particular I frame you can see in that okay in the first line it is also giving the X path of the particular frame in whichever frame
13:28
Speaker A
So now what we need to do is, if you want to interact with these elements inside the frame, we have to switch our driver from page to frame, page to iframe. That means we have to switch to iframe, and once you switch, then we can interact with the elements as usual, just like a normal way.
13:45
Speaker A
an X path and also it will Clearly say it is in I frame and because we want to switch to I frame first for that we need element so this expath of the I frame also given directly here okay
14:00
Speaker A
Okay, and once you have done this, again we have to go back to the main page because our driver is still focused only on the frame. Once you switch it, our driver is there only in the frame. Once your job is done here,
14:15
Speaker A
we can use switch to dot frame and if name of the frame available you can directly pass the name here or if the ID attribute is available for the frame you can directly pass ID in the double quotes and if ID name is not available you can pass that frame as a web element so we need
14:37
Speaker A
and then again you have to come back to the actual page. So what is the command which we have to switch to the frame? It is driver.switchTo().frame(). This is the command.
14:55
Speaker A
different flavors now I'll show you all three first of all let us switch to the frame one so how to switch is driver dot switch to dot frame you can see these are the three options frame and here we can pass the frame and one more also there if you don't have Name ID web element we can also
15:20
Speaker A
But what is the parameter we have to pass here? We can pass the ID of the frame, or we can pass the name of the frame. Sometimes ID, name properties, or attributes we can directly find in HTML.
15:33
Speaker A
here this is a frame first frame and what are the attributes are there for this only SRC attribute is there SRC frame1 do HTML so our uh selector Hub is given uh this Frame xath right this is uh absolute xath not uh partial xath right so you can use this or if you want to create your own EXP
15:59
Speaker A
So we can pass the ID of the frame, or we can pass the name of the frame, or we can identify this entire frame as a web element that you can pass here.
16:13
Speaker A
attributes are available SRC is available so SRC equal to okay in the single or double quotation specify the value of SRC that is frame uncore 1. HTML so this is also matching with the first frame okay so you can also you can create your own xath so let's go back and now here I will pass uh
16:43
Speaker A
So name, ID, or we can directly pass as a web element. So these are the three different options. There are three different flavors. We can directly pass ID if there is an ID here with the double quotes, or if the name is available for the frame, directly you can pass the name.
16:59
Speaker A
will return return the element what is that element frame one so this is a web element this is a web element all right now we can just import this web element now this Frame one we have to pass
17:20
Speaker A
And if ID and name are also not available, then we can find this entire frame as one single web element that you can pass inside the frame.
17:41
Speaker A
not available so we have choosen the third option web element so this command will switch to the frame one switch to frame one so once it is Switched we can interact with the elements now this is the element which is present inside the frame one so this is frame one all right let's
18:09
Speaker A
Okay, this is the process. Now we'll see practically. Me clear this. So first, let us start with, I'll show you multiple examples, and also we have inner frame concept. If you have a frame which contains another frame,
18:43
Speaker A
the first frame and have interacted with this element input box from there I want to switch to frame two okay I want to switch to frame two here also I can enter some value how to do this okay so let us inspect the frame Two
19:03
Speaker A
so how can we handle elements, and once our driver is entered into the frame, how we can again come back to the page. So for every option, we have different methods. We will see one by one.
19:29
Speaker A
trying to interact with the element so driver. find element by. xath xath of the input box do send Keys okay and here I pass some text called cenum okay just observe what we have done in the first step here we have captured the frame element first frame switch to the
19:55
Speaker A
So first, let us start with one example. So I'm taking this page as a sample demo page. Could open three different pages actually, so some...
20:13
Speaker A
get so first frame it is successfully switched and provided the value now if I go back and see the exception here it is still trying to interact with the second element this element it is saying no such element exception so which one this is the element so why is saving no such
20:44
Speaker A
Okay, so it is not giving any frame. So let us take one more example. Let me take another web page actually. That page has got changed.
21:05
Speaker A
you have done the job in the frame one again we have to go back to the page we have to come out from the frame and go back to the page so for this what we need to do is we have another command
21:18
Speaker A
Okay, now let us take some other application. So if I look at here, there are different frames there in this page.
21:44
Speaker A
switch. default content after that we need to go to frame two and then we will able to interact so it will be like this so we cannot directly switch to one frame to another frame so let us say this is end web page and here this is frame one this is the frame two first we switch it to
22:05
Speaker A
This is all one single page. This will give you the entire page, and here this is frame one, which is highlighted with yellow color. Frame two is green color, frame three is blue color, frame four is gray color, frame five is another blue color.
22:18
Speaker A
second frame okay so this is the process so we cannot directly switch to one frame to another frame and for switching back to to the page the command is what driver dot switch to. default content switch to dot default content so this is a one method which we need to remember okay
22:45
Speaker A
So these are the different frames. Totally five frames are there in this page, and again in frame three, there is another form. You can see this is iframe inside frame.
23:07
Speaker A
back here let us see what is a uh attributes of the second frame so this is the frame set and I look at this is the first frame and I think in the frame set there is a second frame available
23:23
Speaker A
So this is actually another frame in frame three. This is another form.
23:46
Speaker A
HTML so this is a frame Two element one element is matching let us see this so now we need to switch to the second frame driver dot switch to dot frame and pass this Frame element this is a web
24:07
Speaker A
Okay, so this is a page. So now let's see how can we handle this. So I want to enter some text inside this box, frame one input box, and this input box is present inside frame one.
24:40
Speaker A
you have captured then you have to pass it inside this Frame so we need to switch to the frame so driver do switch to. frame and here we have to pass frame so this command uh will switch to
24:59
Speaker A
So before that, let us try to see the elements in the dev tools. If I inspect this page,
25:16
Speaker A
you can pass ABC like this directly you can put in the double codes and you don't need to write any locator okay but if it is not available then you can go directly with the frame to like this so we need to get the frame as a web element and then we have to pass it okay
25:34
Speaker A
and this is the HTML. You can see here frameset. Frameset contains a number of frames, and if you expand here, this is a frame, and again the frameset contains another frameset. These are the two different frames, and this is frame one actually.
26:02
Speaker A
to any other frames like we can switch to the frame four we can switch to the frame five and we can switch to the frame three and every frame there is an input box so we can directly switch to
26:13
Speaker A
This is a line which is representing frame one, and if you expand this, there's a document inside this, again one more HTML, body, center. There are many things there.
26:32
Speaker A
to. default content so one more time this will go back to the page okay so these two are the direct frames we have switched to the frame one and then perform the action and come back again we switch to the frame two we perform action and then we come back now I'm going to show
26:49
Speaker A
Okay, so whenever you see the iframe, you can see tag name as frame or iframe. Sometimes you can say iframe as a tag.
27:12
Speaker A
frame okay so actually these are all the different web pages and every web page is put in one single page right so how we will know that if we just inspect this and uh this is an address of the
27:28
Speaker A
Okay, so now let's see how to interact with this element from frame one and go back to your Eclipse. Create new class, sorry, new package, day 30, handle frames.
27:39
Speaker A
HTML is there right so that is SRC link actually if you just copy link address and open this link in another page so you can see this is the actual page this is the yellow page this we embedded into
27:53
Speaker A
Okay, very important concept. Listen to this carefully.
28:07
Speaker A
copy link address and open this another web page so this is the actual frame two so this is also embedded into the current web page so like this there are multiple web pages are embedded into one single web page in the form of frames okay similarly this is also uh if frame this is also
28:29
Speaker A
Okay, so first, we created driver instance, and after that, we launch our application, and then I have maximized this application.
28:45
Speaker A
concept so first we'll go to uh frame three because frame three contains inner I frame okay so in the if frame three we have an input box right let us try to inspect this input box and interact and once it is done let us try to interact with
29:06
Speaker A
Now, step number one, we need to interact with this particular element.
29:37
Speaker A
here Java so we cannot directly interact with this so we have to switch to the frame so if you want to switch to the frame you have to capture the frame as a web element so this is the frame frame three for this we need to write an X path so we are writing
29:59
Speaker A
Okay, I'm not switching to the frame, so let us directly inspect this element, and we'll see directly how can we interact with this, and what kind of exception you are getting.
30:31
Speaker A
XPath okay and uh this we are going to store in a element this is frame three element and this is a web element okay now we need to switch to this Frame three how to switch it driver dot switch to dot frame and here we
30:58
Speaker A
So basically, this is input tag, okay, and this is an XPath of this element. Get this XPath and try to find that element driver.findElement(By.xpath()), and here I want to pass some text here, let's say "welcome."
31:26
Speaker A
currently our driver is present present inside the frame three now we have to interact with the uh I frame inside the frame so this is the frame so which contains multiple elements again if I look at here there are some radio button there are some checkboxes and there is a drop
31:44
Speaker A
Okay, let's say execute this statement, and this element is currently inside the frame.
32:01
Speaker A
we are in frame three itself in the frame three itself we are interacting with the interframe inner frame so which is a part of which is a part of frame three itself okay which is a part of frame three itself now so how to interact with the inner frame
32:31
Speaker A
Okay, it is not done, so let us see the exception. So it is saying no such element exception.
32:56
Speaker A
the inner frame and and then we have to interact with this element okay so once we have interacted with this element again I want to go back to the main page how to go back so our driver is locked
33:10
Speaker A
So why is it saying no such element exception? Because this element is part of the frame. So that is the reason it is unable to find the element with this locator, right?
33:23
Speaker A
it is a single frame or even it is a multiple frames it doesn't matter only one time if if you write default content wherever our driver is present from there it will directly go back to the page so first we need to go to outer I frame then I will go to Inner frame directly
33:39
Speaker A
So if I go back to the Selector Hub, the Selector Hub also will very much help you here. It
33:52
Speaker A
go to the inside the frame inner I frame right so how to go to this inner I frame so if this Frame is having ID or name we can directly use it or we can get this as a web element or by using index
34:04
Speaker A
also we can do it by using index also we can do it but when you have to prefer the index if you have only one single uh frame in your web page then you can choose index concept actually this index we
34:19
Speaker A
cannot get from anywhere else even in HTML also we cannot find them so when we have to prefer index means if you have only one single frame on the web page P then you will prefer indexing concept okay so for example there is a page let us say I have multiple web multiple frames how we will know
34:39
Speaker A
the index of this one index of this index of this index is start from zero only 0 one two okay now when I say 012 which frame is index is zero which frame index is one which one is two we don't know
34:52
Speaker A
right so that is the reason if you have a multiple frames it is very difficult to use indexing here index means just we need to pass the 0 one two like this and if you have a multiple frames we
35:04
Speaker A
don't know which one index is zero which one index is one which one index is two so we don't prefer this but if you have only single frame in this page obviously the index of the page is index
35:15
Speaker A
of the frame is what zero only okay so whenever you find only one single frame on the web page go to the index concept you can directly use zero driver. switch2 frame and you can just pass zero and if ID name is available you can directly pass them and if nothing is available
35:36
Speaker A
get the frame as a web element and then use it okay so now what I'll do is uh in this if frame 3 uh inside the if frame 3 uh we have another frame and there is only one I frame here inside
35:54
Speaker A
the frame three there is only one inside I frame so I'll try to use index concept okay so what I will do is here driver do switch to dot frame zero okay why I'm using zero because there is only one frame so I'm using index so switching to frame switching to frame using index
36:29
Speaker A
okay index so this will directly switch to the inner frame so you don't need to get as a web element again you don't need to use it in the frame nothing only one single statement so that's the reason sometimes if you have ID or name it will be very easy for
36:43
Speaker A
you so driver do switch to do frame of zero this will switch to the inner I frame now we need to interact with some element so how to interact with the element suppose here I have multiple elements now I want to select one of the check radio button here I want to
37:05
Speaker A
select this how to select inspect this element only this element okay and uh if I look at this HTML this is div element right and inside this there is another div element and see you don't find any any proper uh attributes or anything right so what we can do is uh
37:36
Speaker A
you can get the location of the page directly just a second yeah here it is see uh I'm trying to get this element because I don't see any attributes for this element let's say I want to select this checkbox second check second radio button I am a human and this element
38:03
Speaker A
is actually present uh inside this div you can see here inside this div and inside this div okay this is another div element and in this D element there is another D element and here this actual element class equal to something is there right so this is the actual element
38:25
Speaker A
so this element we want to capture and this is a part of uh inner I frame and selector have will not give you inner I frame it is just giving only outer I frame so now we need to
38:39
Speaker A
interact with this element okay so let us see how to interact so what is the attribute we have in this is class there is only one attribute called class so let us try to use this attribute to locate the radar button directly so I'm trying to use it and go to selector
39:00
Speaker A
Hub and uh div is a tag can say d and directly at the rate specify this so I'm trying to use class attribute of the element so zero element why because this element is part of the inner I so we can
39:27
Speaker A
d cannot directly go there so now this element is a part of this above D tag and this is Again part of this above D tag and again this is a part of main D tag here okay so what I'll do is I
39:44
Speaker A
will also try to use another attribute or what we can do is uh we need to capture the link of this particular page so that we can directly open the page and we can get the elements so you can just see you need to find embedded page where exactly this I frame okay if I just
40:07
Speaker A
scroll up uh you can just scroll up little bit like this okay first of all let's go to the yeah this is actual I frame guys okay so this is a part of the frame three if I look at here
40:22
Speaker A
first go to the frame three directly so inside the frame three we have inner frame right so just expand this Frame three and in this you can see document expand it and expand HTML one more time and if you just scroll down you can see one more tag called if frame right actually this is
40:42
Speaker A
the link of this inner iframe this is the link actually okay can just copy this link because it will be very easy to locating elements just copy this SRC link this SRC attribute and open that link in another page okay so once you open now you can see the actual page this is
41:07
Speaker A
the actual page that is embedded into frame three so while capturing this URL and open this in another page and you can see this now here you can easily recognize this elements now I'm inspecting this element I'm a human and here you can find X pass and everything very
41:23
Speaker A
easily because this is the direct page so if I go back and Sor Hub now this is given relative xath directly for this element see this one element is matching so now you can use this uh radio button
41:40
Speaker A
X paath directly in your automation script so here I can say dri dot find element by. XPath this is the element okay dot click so this is how we can can capture the elements which in which are there in the if frame so because this is somehow we will feel difficulty because this
42:06
Speaker A
is inner I frame uh if you even though if you write right locator here selector Hub cannot go inside the if frame and find that element so we are doubt about this whether our locator is correctly identifying location locate or not so what we need to do we need to directly go
42:23
Speaker A
to this URL of the web page and open that URL another page you will get the plain form or page and here you can easily locate element and whichever element you want to interact you can get the locator for that element and you can use it here so here I'm selecting one
42:38
Speaker A
radio button which is there inside the inner frame okay so let us save it and then execute okay just observe we are able to interact with the radio button which is got selected and similarly you can also locate any of this element and you can also select the checkbox and drop
43:14
Speaker A
downs is still not discussed so I leave this for now can handle these elements okay so once it is done again how to come back to the main page again default content driver. switch2 do default content which we can use to come out from the page so this will come out from the
43:33
Speaker A
page okay so like this we can run the code again okay now it is perfectly working fine okay sometimes if it is not able to with this element you will get some element intercepted exception element clickable exception okay sometimes you
44:04
Speaker A
may get those type of exceptions so how to handle them instead of directly clicking on this element try to use JavaScript executor okay in the next sessions I will detail explain about this suppose if you want to do the same action by using JavaScript executor first we need to
44:23
Speaker A
capture this element in a variable let us say I'm storing this element so this is my radio button and this is a web element okay so once you get an element now we need to click on this element using JavaScript executor so for that we need to create uh we need to send the
44:49
Speaker A
driver to JavaScript executor so I can say JavaScript and we have a separate session for this JavaScript executor alone there are a lot of things we need to understand this but now just I'm giving work around if something is not working directly you
45:04
Speaker A
can use this alternatively and whenever you are getting element intercepted exception element is not clickable exception especially when you get these two exceptions you can try this JavaScript executor JS equal to we'll assign the driver to this JavaScript executor after typ casting
45:24
Speaker A
this JavaScript execut so we need to import this JavaScript executor from org open. selenium and once we have done it now by using JS we have to call one method called execute script execute script JS dot execute script and here we need to pass two parameters the
45:57
Speaker A
first parameters is arguments of zero comma arguments of zero do click we need to call a method called click semicolon and here we have to pass element on which element you have to click you can pass it so for radio button checkbox link normal button for everything this is the
46:17
Speaker A
same process get the element and uh use this JavaScript executor so this will also do the same thing so instead of directly clicking on this element selecting the radio button I'm getting the radio button into variable and through JavaScript executor I'm performing the
46:36
Speaker A
action okay so this will also do the same job okay very simple so this is how we can handle the frames only thing is you need to remember this command Okay so yesterday we have already discussed about checkboxes concept so please check that
47:06
Speaker A
one so yesterday we have I think yesterday only we have discussed more about checkboxes how to select specific checkbox how to select multiple checkboxes how to select uh few checkboxes based on the condition so we already covered that concept please go
47:24
Speaker A
through yesterday's session if you're not attended please go through the we videos okay so guys are you clear everyone so how to handle the frames okay so far we have learned three types of switching commands three types of switching
47:49
Speaker A
commands do you guys remember there are three types of uh switching commands we learned or we can say switching methods how to switch between the browser windows do you guys remember how to switch between the browser windows second concept switch between the alerts switch between
48:19
Speaker A
the how to switch between the alerts now today's concept is how to switch between the frames how to switch between the browser windows One browser window to another browser window the command is what driver dot switch to switch to do window right here we have to pass window handle right
48:44
Speaker A
window ID we have to pass driver. s. window so here we have to pass window ID or window handle and how to get window ID or window handle by using get window handle or get window handles right so this we already covered now to switch between the alerts what is the command we use
49:05
Speaker A
driver dot switch to dot alert okay this command we have to use which will return the alert and to close alert window to by using okay or by using cancel button we have to call accept or dismiss accept we discussed and this is another method is what dismiss right so this is also we discussed
49:36
Speaker A
last class now today we discussed about switch between the frames how to switch between the frames driver dot switch to do frame here we can pass ID if it is available in the coming sessions we will see so many frames okay so alternative I will try to use ID sometimes
49:57
Speaker A
name sometimes and today we already seen web element so multiple things and index also sometimes we can use if you have only single frame we can use index also sry ID so here you can use name if the name is available for the frame we can also use name availability and then you can also
50:16
Speaker A
par frame as a web element so different things so these are three types of switch commands we can switch between the browser windows we can switch between the alerts we can switch between the frames okay so just remember this very important uh Concepts now I will give you an assignment
50:39
Speaker A
based on this frames topic you guys can try on the same web page okay on the same uh frame actually I have another assignment I will also give you in the notepad later so for the in this particular frame so what you have to do is as part of assignment you need to uh go to the frame five
51:03
Speaker A
so in the frame five there is a input box okay and uh you can interact with this input box if possible also in the frame five there is a one link here okay there is a one link you need to
51:18
Speaker A
click on this link so once you click on this link it will open another frame you can see another page so once you click on that link then it will open the page Dynamic page okay so now we need to go to this particular page you need to again switch to this particular frame and
51:39
Speaker A
you can do whatever operations you want you can just check this logo present or not or you can just click on uh something whatever you want there are so many links so many elements and this is some searchbox email address whe you can interact so you can do whatever you want on this
51:57
Speaker A
and how we will get this you have to click on this link this is initial stage so you need to click on this link in the frame five and then you'll get this page again this is inner frame okay inside the frame five you will find another frame so try
52:15
Speaker A
to interact with these elements this is one assignment and uh also I will give you another assignment guys can try that I forgot that page uh later I will copy in the notepad right so go to this page and go to fifth frame or switch to the fif all right
52:49
Speaker A
switch to fifth frame and click on the link opens a new I frame switch to iron frame and check logo presence uh in the logo presence in the inner frame so this is a one present or not you can
53:07
Speaker A
check this is one assignment and I will also add one more assignment uh you guys can check just a second give me a few seconds I'm trying to find out the page so this is all for today's session okay I will stop here because I need to start
53:54
Speaker A
another concept but that will take another one hour time so tomorrow we'll skip the tomorrow session okay so if you have any questions uh you can ask or else we'll wind up the session
Topics:SeleniumJavaframesiframesnested iframesdriver.switchTo()NoSuchElementExceptionweb automationframe handlingSDET QA

Frequently Asked Questions

What is the difference between a frame and an iframe?

A frame and an iframe both embed one web page inside another, but they differ in implementation. Frames are part of the HTML frameset, while iframes are inline frames embedded within a page. However, Selenium handles both similarly.

Why can't Selenium directly interact with elements inside frames?

Selenium's driver focuses on the main page by default and cannot directly access elements inside frames or iframes. You must switch the driver context to the specific frame before interacting with its elements.

How do you switch to a frame in Selenium?

You can switch to a frame by passing its ID, name, or WebElement to the driver.switchTo().frame() method. This changes the driver's context to the frame, allowing interaction with its elements.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →