Monday 23 May 2016

Frame Handling

Working with Frames in Selenium Webdriver


What is iFrame ?

An iFrame (Inline Frame) is an HTML document embedded inside the current HTML document on a website. iFrame HTML element is used to insert content from another source, such as an advertisement, into a Web page. A Web designer can change an iFrame's content without making them reload the complete website. A website can have multiple frames on a single page. And a frame can also have inner frames (Frame in side a Frame).

In Selenium to work with iFrames, we have different ways to handle frame depending on the need. Please look at the below ways of handling frames
Select a frame by its (zero-based) index. That is, if a page has multiple frames (more than 1), the first frame would be at index "0", the second at index "1" and so on.
Once the frame is selected or navigated , all subsequent calls on the WebDriver interface are made to that frame. i.e the driver focus will be now on the frame. What ever operations we try to perform on pages will not work and throws element not found as we navigated / switched to Frame.

Returns: driver focused on the given frame (current frame)
Throws: NoSuchFrameException - If the frame is not found.


public void switchToFrame(int frame) { try { driver.switchTo().frame(frame); System.out.println("Navigated to frame with id " + frame); } catch (NoSuchFrameException e) { System.out.println("Unable to locate frame with id " + frame + e.getStackTrace()); } catch (Exception e) { System.out.println("Unable to navigate to frame with id " + frame + e.getStackTrace()); } }

Parameters: name Or Id - the name of the frame or the id of the frame element.
Returns: driver focused on the given frame (current frame)
Throws: NoSuchFrameException - If the frame is not found


public void switchToFrame(String frame) { try { driver.switchTo().frame(frame); System.out.println("Navigated to frame with name " + frame); } catch (NoSuchFrameException e) { System.out.println("Unable to locate frame with id " + frame + e.getStackTrace()); } catch (Exception e) { System.out.println("Unable to navigate to frame with id " + frame + e.getStackTrace()); } }


Parameters: Index - (zero-based) index
Example: if iframe id=webklipper-publisher-widget-container-frame, it can be written as driver.switchTo().frame("webklipper-publisher-widget-container-frame"); Below is the code snippet to work with switchToFrame using frame id.


33 comments:

  1. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai blog

    ReplyDelete
  2. Best blog.Got to learn new things.Thanks for this Blog SAP HR Training in Chennai blog

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Appreciable! The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking training / cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.

    ReplyDelete
  5. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
    Digital Marketing online training

    full stack developer training in pune

    full stack developer training in annanagar

    full stack developer training in tambaram

    full stack developer training in velachery

    ReplyDelete
  6. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
    java training in chennai | java training in bangalore


    java training in tambaram | java training in velachery

    ReplyDelete
  7. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    Air Hostess Training in Chennai | Air Hostess Training Institute in Chennai | Air Hostess Academy in Chennai | Air Hostess Course in Chennai | Air Hostess Institute in Chennai

    ReplyDelete
  8. Useful content. Thanks for Sharing. It shows your indepth knowledge on the subject. Pls keep updating.

    Article submission sites
    Guest posting sites

    ReplyDelete
  9. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    CCNA Training in Chennai
    DevOps Training in Chennai
    DevOps foundation certificate
    DevOps institute certification
    CCNA course in Chennai
    CCNA Training institute in Chennai

    ReplyDelete
  10. good work done and keep update more.i like your information's and
    that is very much useful for readers.
    Angular Training in Bangalore
    Angular JS Training courses near me
    AngularJS Training Institutes in Vadapalani

    ReplyDelete
  11. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

    AWS Interview Questions And Answers

    AWS Training in Pune | Best Amazon Web Services Training in Pune

    AWS Training in Chennai |Best Amazon Web Services Training in Chennai


    AWS Training in Chennai | Best AWS Training in Chennai


    Amazon Web Services Training in Pune | Best AWS Training in Pune

    ReplyDelete
  12. It is really a great pleasure reading your article. I have learned a lot of new things from your blog. Keep updating more like this

    C C++ Training in Chennai | C Training in Chennai | C++ Training in Chennai | C C++ Training in Velachery | C C++ Training in Adyar | C C++ Training in Tambaram

    ReplyDelete
  13. You are doing a great job. I would like to appreciate your work. clearly explained
    Regards
    Machine Learning Training institute

    ReplyDelete
  14. I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.
    C and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery

    ReplyDelete
  17. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.keep on search.
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  18. Have you heard about the offer that is going on in our institution. So here is the offer to tell you guys. We are conducting CS executive classes and free of cost CSEET classes only for you guys . Hurry up contact us or visit our website at https://uniqueacademyforcommerce.com/

    ReplyDelete
  19. The RMB TO USD Converter Is Updated Every 15 Minutes. You Can Set It To Alert You Whenever The Rate Changes.

    ReplyDelete
  20. Want To Trade Forex With AVATRADE REVIEW ? Read This Blog First To Find Out About The Best Forex Trading Conditions. We Review The Most Popular Forex Brokers And Tell You What You Need To Know.

    ReplyDelete
  21. شما به واسطه تزریق ژل می توانید بسیاری از مشکلات پوستی خود را برطرف کنید.
    https://drkhaliliclinic.com/gel-injection/
    زیبایی هرچه بیشتر چهره با تزریق ژل

    ReplyDelete
  22. Nice post. Thanks for sharing such a worthy information.
    jewellery erp software
    Jewellery erp Software

    ReplyDelete
  23. Nice post. Thanks for sharing such a worthy information.
    Jewellery ERP Software UAE
    Jewellery ERP Software UAE

    ReplyDelete