Home > Software engineering >  iframe name changes each time the page is reloaded
iframe name changes each time the page is reloaded

Time:10-07

i'm having a problem with my script in pyhton. Each time when the web page that im using opens the iframe src changes.

  By.CSS_SELECTOR,"iframe#IFRAME_muVN"

(For example de code above is the current iframe when i copy with css selector) But when i enter to the web page again the name of that iframe changes.

#IFRAME_6Eh8

is there a way to manage that change of the iframe, because im allways getting timeout due to the webdriver wait and the iframe element is never gonna be found.

this is my code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from datetime import date
import time 



s=Service(r'C:\Users\dbayona\Webdriver\chromedriver.exe')
driver = webdriver.Chrome(service = s)
driver.maximize_window()

driver.get('http://190.109.11.66:8888/BOE/BI')
iframe = driver.find_element(By.NAME, "servletBridgeIframe") 
driver.switch_to.frame(iframe)
username = driver.find_element(By.XPATH, '//*[@id="_id0:logon:USERNAME"]')
username.send_keys("*****")
password = driver.find_element(By.XPATH, '//*[@id="_id0:logon:PASSWORD"]')
password.send_keys("*****")
login = driver.find_element(By.XPATH, '//*[@id="_id0:logon:logonButton"]')
login.click()
iframe =WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#iframeHome-122668")))
driver.implicitly_wait(15)
dropdown = driver.find_element(By.XPATH, '//*[@id="header3_5"]')
dropdown.click()
storesense = driver.find_element(By.XPATH, '//*[@id="li_item_0_4_1"]')
driver.implicitly_wait(5)
storesense.click()
iframe = WebDriverWait(driver, 120).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#IFRAME_muVN")))
date = driver.find_element(By.XPATH, '//*[@id="date-picker"]')
today = date.today()
d1 = today.strftime("%d/%m/%Y")
date.send_keys(d1)
driver.switch_to.default_content()

Code where im trying to find the iframe:

 iframe = WebDriverWait(driver, 120).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#IFRAME_muVN")))

image of the iframe:

Iframe of the page

CodePudding user response:

Since the element is dynamic try the following css selector. ^ means startswith

iframe = WebDriverWait(driver, 120).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='IFRAME_']")))

CodePudding user response:

try to find by tag name <iframe> but make sure if you not have multiple tag name like this inside the element that its related to

  • Related