Select Iframe Using Python + Selenium

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



Leave a reply



Submit