Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Selenium: Python Webdriver to get elements from popup iframe does not find the elements

  • 12-01-2023 12:17PM
    #1
    Registered Users, Registered Users 2 Posts: 5,753 ✭✭✭



    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[@class="pdynamicbutton"]//a[@class="call"]
    

    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.



Comments

  • Registered Users, Registered Users 2 Posts: 7,098 ✭✭✭Talisman


    The HTML tag for the iframe has a number of properties which you can use to locate the element with the webdriver.

    <iframe src="https://consent-pref.trustarc.com/?type=oracle7&amp;site=oracle.com&amp;action=notice&amp;country=ie&amp;locale=en&amp;behavior=expressed&amp;gtm=1&amp;layout=default_eu&amp;irm=undefined&amp;from=https://consent.trustarc.com/" 
    id="pop-frame07633610403275147" 
    title="TrustArc Cookie Consent Manager" 
    tabindex="1" 
    scrolling="no" 
    class="truste_popframe" 
    name="trustarc_cm"></iframe>
    

    Find the iframe using its title property:

    from selenium.webdriver.common.by import By
    
    iframe = driver.find_element(By.XPATH, "//iframe[@title='TrustArc Cookie Consent Manager']")
    

    Alternatively, use the name property to locate the iframe:

    iframe = driver.find_element(By.XPATH, "//iframe[@name='trustarc_cm']")
    

    With a reference to the iframe, switch the webdriver frame and click the button:

    driver.switch_to.frame(iframe)
    btn = driver.find_element(By.XPATH, "//div[@class='pdynamicbutton']/a[@class='call']")
    btn.click()
    


Advertisement