Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 12-01-2023 12:17pm
    #1
    Registered Users Posts: 5,553 ✭✭✭



    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 Posts: 6,149 ✭✭✭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