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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 12-01-2023 11:17am
    #1
    Registered Users, Registered Users 2 Posts: 5,659 ✭✭✭



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