How to Handle Frames in Selenium WebDriver

  Рет қаралды 57,675

H Y R Tutorials

H Y R Tutorials

4 жыл бұрын

In this video, I have shown how we can handle Frames in Selenium WebDriver.
Frames are a now deprecated means of building a site layout from multiple documents on the same domain. You are unlikely to work with them unless you are working with a pre-HTML5 web app. Iframes allow the insertion of a document from an entirely different domain and are still commonly used.
To interact with any control inside the frame, we will need to first switch to the frame, in a similar way to how we switch windows. WebDriver offers three ways of switching to a frame.
1) Using an index
2) Using a name or ID
3) Using a WebElement
----------- Using an index: -----------------
It is possible to use the index of the frame to switch to that frame, such as can be queried using window.frames in JavaScript.
Here the index starts from 0(zero)
Example:
// Switches to the second frame
driver.switchTo().frame(1);
----------- Using a name or ID -----------------
If your frame or iframe has an id or name attribute, this can be used instead. If the name or ID is not unique on the page, then the first one found will be switched to.
Example:
//Using the ID
driver.switchTo().frame("testframe");
//Or using the name instead
driver.switchTo().frame("frm1");
//Now we can click the button
driver.findElement(By.tagName("button")).click();
----------- Using a WebElement -----------------
Switching using a WebElement is the most flexible option. You can find the frame using your preferred selector and switch to it.
Example:
//Store the web element
WebElement iframe = driver.findElement(By.xpath("//h1[.='Frame1']/following-sibling::iframe"));
//Switch to the frame
driver.switchTo().frame(iframe);
//Now we can click the button
driver.findElement(By.tagName("button")).click();
-------------- Leaving a frame -----------------------
To leave an iframe or frameset, switch back to the default content like so:
Example:
// Return to the top level
driver.switchTo().defaultContent();
--------------- Going to parent frame -----------------
When you are in nested frames and you want to come back to the parent frame of all the child frames then we use a method called parentframe.
Example:
driver.switchTo().frame("testframe1");
driver.switchTo().frame("testChildFrame1");
driver.switchTo().frame("testChildFrame11");
//Return to parent frame
driver.switchTo.parentFrame();
==============================================
************* Checkout my other playlists *************
==============================================
Java Programming videos playlist:👇
🔗 bit.ly/3keRJGa
Selenium WebDriver with Java videos playlist:👇
🔗 bit.ly/2FyKvxj
Selenium interview questions videos playlist:👇
🔗 bit.ly/3matUB3
Windows automation with FlaUI videos playlist:👇
🔗 bit.ly/33CG4dB
CSS Selectors videos playlist:👇
🔗 bit.ly/2Rn0IbD
XPath videos playlist:👇
🔗 bit.ly/2RlLdkw
Javascript Executor videos playlist:👇
🔗 bit.ly/2FhNXwS
Apache POI videos playlist:👇
🔗 bit.ly/2RrngrH
Maven videos playlist:👇
🔗 bit.ly/2DYfYZE
How to fix Eclipse errors:👇
🔗 bit.ly/3ipvNYf
==============================================
==============================================
Connect us @
🔗 Website - www.hyrtutorials.com
🔗 Facebook - HYRTutorials
🔗 LinkedIn - www.linkedin.com/company/hyrtutorials
🔗 Twitter - Hyrtutorials
==============================================
==============================================
🙏 Please Subscribe🔔 to start learning for FREE now, Also help your friends in learning the best by suggesting this channel.
#webAutomation #selenium #frames #hyrtutorials

Пікірлер: 79
@HYRTutorials
@HYRTutorials 4 жыл бұрын
Please use the below link for the selenium videos playlist: 🔗 bit.ly/2FyKvxj
@anoopsahu435
@anoopsahu435 2 жыл бұрын
how to switch from 5th frame to 4th frame in case if all are nested?
@RandomFromInternet419
@RandomFromInternet419 2 жыл бұрын
Обожаю туторы этого прекрасного народа. Мемы мемами, а полезность коллосальная. :)
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Thankyou buddy
@angaraki
@angaraki 3 жыл бұрын
Thank you. You explain patiently & with sincerity. Thanks again.
@HYRTutorials
@HYRTutorials 3 жыл бұрын
So nice of you
@subhasrinayak3670
@subhasrinayak3670 Жыл бұрын
Excellent explanation sir, I had a fear to automate frames, but you recovered me from this. Thank you so much
@HYRTutorials
@HYRTutorials Жыл бұрын
Thanks buddy 😊
@syedsharoz1748
@syedsharoz1748 Жыл бұрын
Explained in very good manner. Thank you Comrade.
@HYRTutorials
@HYRTutorials Жыл бұрын
Thanks buddy 😊
@saxenahimanshu6584
@saxenahimanshu6584 3 жыл бұрын
It's one of kind of Website you created is superb work to understand the concept, i have to say tons of thanks
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Glad to hear that
@sulthanarazia2014
@sulthanarazia2014 6 ай бұрын
really so help full, crystal clear explanation thank you sir
@ChethanCP
@ChethanCP 2 жыл бұрын
Awesome. Thanks a lot for the very clear explanation
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Thankyou 😊
@factsofallahal-shaheedserv7816
@factsofallahal-shaheedserv7816 2 жыл бұрын
If you find this video is not clear, you can watch this video with good , the link is in 1st comment. The content of the video is good, explained in simple way
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Thank you
@marsoniyahem3632
@marsoniyahem3632 Жыл бұрын
Thanks for the explanation, you made my day.
@HYRTutorials
@HYRTutorials Жыл бұрын
Happy learning buddy 😊
@basithtafadher4673
@basithtafadher4673 3 жыл бұрын
Thanks for your excellent lectures
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Thankyou, keep watching 😊
@lightinlight
@lightinlight 2 жыл бұрын
thank you , i can understand it very well now
@HYRTutorials
@HYRTutorials 2 жыл бұрын
That's good to hear buddy 🙂
@Ambitious675
@Ambitious675 Жыл бұрын
Loved your explanation. Thank you
@HYRTutorials
@HYRTutorials Жыл бұрын
Thanks buddy 😊
@tgrakesh8gmail
@tgrakesh8gmail 4 жыл бұрын
Learning a lot from ur videos...clear explanation..thanks for sharing the videos....waiting for CSS selector videos..👍
@HYRTutorials
@HYRTutorials 4 жыл бұрын
Thankyou. Soon will create them.
@soniappriya.
@soniappriya. 6 ай бұрын
Thank you so much 🎉 It helped me😊
@travelwithme9998
@travelwithme9998 4 жыл бұрын
Amazing job
@HafizurRahman-dr3xe
@HafizurRahman-dr3xe 2 жыл бұрын
Hey H Y R Tutorial Your lecture is very Impressive Thank you for your effort Have a good one
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Thanks buddy
@niharika3375
@niharika3375 3 жыл бұрын
Very helpful pls keep more vedios on selenium
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Yes, sure
@studiesonsoftwaretesting9768
@studiesonsoftwaretesting9768 Жыл бұрын
well explained.great job
@HYRTutorials
@HYRTutorials Жыл бұрын
Thanks buddy 😊
@akshaysagare5378
@akshaysagare5378 3 жыл бұрын
Very good explanation
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Thankyou 😊
@lekkalasuvarchala12
@lekkalasuvarchala12 2 жыл бұрын
Clear explanation broo😊
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Thankyou buddy 😊
@chirunomulavenkatesh
@chirunomulavenkatesh 3 жыл бұрын
Brilliant explanation 🙂 , I have a question , can we handle the elements inside the frames using javascript executor interface ??
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Yes, absolutely After you switch to the target frame, driver now points to that frame content. So you can perform any kind of operation like javascriptexecutor operations.
@Vasantha999vlogs
@Vasantha999vlogs 2 жыл бұрын
Thank you
@HYRTutorials
@HYRTutorials Жыл бұрын
Welcome buddy 😊
@jagratsahoo6885
@jagratsahoo6885 2 жыл бұрын
Thanks HYR
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Welcome buddy
@purvidholakia3570
@purvidholakia3570 3 жыл бұрын
Nice Explanation. Is it possible to calculate the time load for using javascript or listeners?
@HYRTutorials
@HYRTutorials 3 жыл бұрын
I don't think so @Purvi
@purvidholakia3570
@purvidholakia3570 3 жыл бұрын
@@HYRTutorials Thanks, that is the task given to me.
@chayae3740
@chayae3740 3 жыл бұрын
Tqu sir
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Glad you liked it
@Narain346
@Narain346 6 ай бұрын
I have observed one small thing, if we are using thread.sleep, then frame switching with index will not work but frame switching with id or name will work; is this a known issue
@SiddharthKaleFilms
@SiddharthKaleFilms 26 күн бұрын
what is difference between frame and ? is it different
@rvj9220
@rvj9220 7 ай бұрын
Hi I would like to know if you are conducting some training sessions for Java + Selenium automation testing?
@जिंदगी_ए_सफर
@जिंदगी_ए_सफर 2 жыл бұрын
Excellent video. Please give code of program
@HYRTutorials
@HYRTutorials 2 жыл бұрын
I dont have that copy now buddy. You can pause the video and note the program
@RoyerAdames
@RoyerAdames 3 жыл бұрын
How do you handle the case when you reload the page and all the get detached?
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Even if you reload the page, the frames will be attached again by the time page loading is complete.
@swapnabhaskaruni
@swapnabhaskaruni 2 жыл бұрын
can we use switchto default content while handling windows
@HYRTutorials
@HYRTutorials 2 жыл бұрын
Nope This method is designed for frames only
@anoopsahu435
@anoopsahu435 2 жыл бұрын
how to switch from 5th frame to 4th frame in case if all are nested
@HYRTutorials
@HYRTutorials 2 жыл бұрын
It's the same process buddy. You just need to understand where your driver focus is present and where is your target frame.
@vinendramogatadakala1623
@vinendramogatadakala1623 2 жыл бұрын
I have a power bi report inside Iframe where I am trying to download the report to excel, I tried the same code but no luck can you help meI have a power bi report inside Iframe where I am trying to download the report to excel, I tried the same code but no luck can you help me
@HYRTutorials
@HYRTutorials 2 жыл бұрын
At what stage you are struck buddy? Are you getting any exception? Send me the code and screenshot on hyadagirireddytutorials@gmail.com
@nripendramohanshrivastava6255
@nripendramohanshrivastava6255 2 жыл бұрын
Can we handle whose visibility is hidden
@HYRTutorials
@HYRTutorials 2 жыл бұрын
I dont think we can do that. But why do u want to handle the hidden frames?
@Solution4uTx
@Solution4uTx 3 жыл бұрын
Hi I am trying to logging with Frame handling but still couldn't figure out still getting NoSuchElement exception package AutoSel; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; import io.github.bonigarcia.wdm.WebDriverManager; public class skiptest { public static void main(String[] args) throws InterruptedException { WebDriverManager.chromedriver().setup(); ChromeOptions options =new ChromeOptions(); WebDriver driver =new ChromeDriver(options); options.addArguments("--start-maximized","--incognito"); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); DesiredCapabilities caps = new DesiredCapabilities(); caps.setAcceptInsecureCerts(true); options.merge(caps); driver.get("www.skipthedishes.com/"); //Thread.sleep(2000); driver.findElement(By.xpath("//button[@aria-label='Log In']")).click(); //Thread.sleep(2000); driver.switchTo().frame(driver.findElement(By.id("ssIFrame_google"))); driver.findElement(By.xpath("//div[contains(text(),'Email')]/ancestor::button")).click(); driver.switchTo().defaultContent(); Thread.sleep(2000); driver.quit(); } }
@HYRTutorials
@HYRTutorials 3 жыл бұрын
Actually you don't need to handle the frame here. Because the "Login with Email" button is not present inside any frame. So remove the frame handling code and execute the script.
@Solution4uTx
@Solution4uTx 3 жыл бұрын
@@HYRTutorials thank you so much. did you post any tutorials on Grid and selenium cucumber
@yadagirireddy2632
@yadagirireddy2632 3 жыл бұрын
@@Solution4uTx not yet but will create them
@sumitbhawal6893
@sumitbhawal6893 Жыл бұрын
Code explanation starts at 10:10.
@HYRTutorials
@HYRTutorials Жыл бұрын
Yup
@pradideepu7273
@pradideepu7273 Жыл бұрын
Frames switching is taking more execution time, Is there any solution?
@HYRTutorials
@HYRTutorials Жыл бұрын
No buddy
@i4iirfan
@i4iirfan Жыл бұрын
Sir I am facing issues in chat bot to switch frame please help me out I am on job
@HYRTutorials
@HYRTutorials Жыл бұрын
What's the issue you are facing?
@i4iirfan
@i4iirfan Жыл бұрын
@@HYRTutorials I am facing issue in testing chatbot
@HYRTutorials
@HYRTutorials Жыл бұрын
@@i4iirfan what issue buddy
Capture Screenshots using Selenium WebDriver | Selenium WebDriver |
19:44
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 25 МЛН
Sigma Kid Hair #funny #sigma #comedy
00:33
CRAZY GREAPA
Рет қаралды 39 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 10 МЛН
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 25 МЛН
How to handle iframes in Selenium WebDriver
13:00
Magnetic Automation and Learnings
Рет қаралды 21 М.
How to Handle Frames in Selenium Webdriver
27:03
Mukesh otwani
Рет қаралды 113 М.
How to Handle Frames in Selenium WebDriver - Session 4a
20:47
Naveen AutomationLabs
Рет қаралды 175 М.
How I'd Learn Web Development (If I Could Start Over)
6:55
Dylan Cole
Рет қаралды 541 М.
Handle Hidden Drop Down Values / Auto Suggestions using DOM Trick | EventListener
7:55
Handling of Bootstrap Dropdowns using #Selenium WebDriver | Selenium |
37:03
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 25 МЛН