Home > front end >  Selenium: Python Webdriver to get elements from popup iframe does not find the elements
Selenium: Python Webdriver to get elements from popup iframe does not find the elements

Time:01-13

In the case of the URL

https://console.us-ashburn-1.oraclecloud.com/

where it pops up to accept cookies, I try to click the button element to allow/deny cookies

//div[@]//a[@]

but it is not seen.

When I use

switch_to.frame('trustarcNoticeFrame')

It still does not find it.

Not sure how i can get at these buttons for login.

CodePudding user response:

The problem is that this switch_to.frame('trustarcNoticeFrame') does not switch to the iframe which has the cookie manager dialog. Here is the code snippet that works for me.

btnYes = "//div[@class='pdynamicbutton']/a[@class='call']"
iframe = "//iframe[@title='TrustArc Cookie Consent Manager']"

ifr = driver.find_element(By.XPATH, iframe)
driver.switch_to.frame(ifr)

eleYes= driver.find_element(By.XPATH, btnYes)
eleYes.click()

CodePudding user response:

Use WebDriverWait and wait for frame to be available and then switch.

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.truste_popframe")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Accept all']"))).click()

You need to wait for below libraries.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
  • Related