import time


def get_all_ads(listing_balise,ads_balise,driver):
    """ Find all ads in the webpage

    We'll be using this function to find all ads available on the webpage in order to click on each
    one of them.

    Args:
        listing_balise (str) : html balise used to find the "block" of ads we are looking to collect
                               a "block" correspond to the last block of ads loaded while itering through
                               the webpage
        ads_balise (str) : html balise used to find each ads links inside the "block"
        driver : a driver object, return from webdriver.Chrome
    
    Return:
        all_ads (list) : a list of link to open all ads available
    """
    # find the last listing loaded
    listing = driver.find_elements_by_css_selector(listing_balise)
    
    # Get all ads from the last listing available
    
    all_ads = listing[-1].find_elements_by_css_selector(ads_balise)
    time.sleep(5)
    
    return(all_ads)