Select iframe using Python + Selenium
What finally worked for me was:
sel.run_script("$('#upload_file_frame').contents().find('img[alt=\"Humana\"]').click();")
Basically, don't use selenium to find the link in the iframe and click on it; use jQuery. Selenium has the capability to run an arbitrary piece of javascript apparently (this is python-selenium, I am guessing the original selenium command is runScript or something), and once I can use jQuery I can do something like this: Selecting a form which is in an iframe using jQuery
Python selenium How to click an element in iframe?
The element you are looking after is inside nested iframe
. You need to switch both the
iframes.
Use following css selector to identify the iframe
.
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='landingpage']")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src*='plus.web.de']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "save-all-conditionally"))).click()
Or Use below xpath
to identify the iframe.
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='landingpage']")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@src,'plus.web.de')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "save-all-conditionally"))).click()
How to enter text in an iframe with Selenium and Python
There is an iframe
<iframe frameborder="0" hspace="0" scrolling="no" src="/GBS/Authentication/Authenticate?redirectUrl=%2FGBS%2FProject&requestMode=Setup&isIframe=True" allowtransparency="true" style="border: none; width: 345px; height: 513px;"></iframe>
You can do the following to swap to it.
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//*[@id='oxygen-container']/iframe")))
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Here's the full thing
driver.get("https://gbs.autodesk.com/GBS/")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Sign In"))).click()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//*[@id='oxygen-container']/iframe")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "userName"))).send_keys("test@mail.com")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "verify_user_btn"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "password"))).send_keys("mypassword")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "btnSubmit"))).click()
How to change between iframes in Selenium and Python
//iframe[@class='viewer pbi-frame']
Should be a simple xpath using driver.switch_to.frame()
Or
//iframe[@title='Power BI Report Viewer']
Select element from a list inside an iframe using python selenium
There are total 4 iframes.
The table you want to interact with is in iframe[src^='https://freeserv']
and parent iframe is widget-container
. One by one you have to switch to it like this :
Code :
wait = WebDriverWait(driver,10)
driver.maximize_window()
driver.get("https://www.dukascopy.com/trading-tools/widgets/quotes/historical_data_feed")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "widget-container")))
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='https://freeserv']")))
check_Box = wait.until(EC.visibility_of_element_located((By.XPATH, "//strong[text()='EUR/TRY']/../preceding-sibling::span/span")))
ActionChains(driver).move_to_element(check_Box).perform()
check_Box.click()
Related Topics
Multi Platform Portable Python
Check If One Package Is Installed in My System with Python
What Does "The Following Packages Will Be Superseded by a Higher Priority Channel" Mean
How to Upload File with Python Requests
How to Extract Text from a PDF File
How to Set Time Limit on Raw_Input
Convert Pandas Column Containing Nans to Dtype 'Int'
Regular Expression to Match a Dot
Find the Most Common Element in a List
Writing a Python List of Lists to a CSV File
Problems Adding Path and Calling External Program from Python
Storing Value from a Parsed Ping
Pytest Running with Another Version of Python
Custom Sorting in Pandas Dataframe
Using Property() on Classmethods
What's the Correct Way to Convert Bytes to a Hex String in Python 3
Pip How to Remove Incorrectly Installed Package with a Leading Dash: "-Pkgname"