- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Select iframe using Python and Selenium
We can select iframe with Selenium webdriver. An iframe is identified with a <iframe> tag in an html document. An iframe is an html document containing elements which resides inside another html document.
Let us see a html document of a frame.
The following methods help to switch between iframes−
switch_to.frame(args) – The frame index is put as an argument to the method. The starting index of iframe is 0.
Syntax−
driver.switch_to.frame(0), switching to the first iframe.
switch_to.frame(args) - The frame name or id is put as an argument to the method.
Syntax−
driver.switch_to.frame("nm"), switching to the iframe with name nm.
switch_to.frame(args) - The frame webelement is put as an argument to the method.
Syntax−
driver.switch_to.frame(f),switching to the iframe with webelement f.
switch_to.default_content() – To shift to the parent page from the iframe.
Syntax−
driver.switch_to.default_content()
Example
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.get("https://the-internet.herokuapp.com") driver.find_element_by_link_text("Frames").click() driver.find_element_by_link_text("Nested Frames").click() # switch to frame with name driver.switch_to.frame("frame-bottom") # identify element and get text method s = driver.find_element_by_xpath("//body").text print ("Test inside frame: " + s) # move out of frame to parent page driver.switch_to.default_content() driver.quit()
Output
- Related Articles
- Selenium and iframe in html.
- Find elements inside forms and iframe using Java and Selenium WebDriver.
- Using Selenium in Python to click/select a radio button.
- How to select element using XPATH syntax on Selenium for Python?
- Handling DropDown And Multiple Select in Webdriver using Selenium
- How to Select date from a datepicker with Selenium Webdriver using Python?
- How to select checkboxes using selenium java webdriver?
- How to Select Value from DropDown using Selenium Webdriver?
- How do I select elements inside an iframe with Xpath?
- Fill username and password using selenium in python.
- Using Extensions with Selenium & Python
- Remove border from IFrame using CSS
- How to select value from a drop down using Selenium IDE?
- Running javascript in Selenium using Python.
- How to select a drop-down menu option value with Selenium (Python)?
