from functools import partial
from selenium.webdriver import Firefox
from selenium.webdriver.support.ui import (
    WebDriverWait
)


def esperar_elemento(elemento, webdriver):
    print(f'Tentando encontrar "{elemento}"')
    if webdriver.find_elements_by_css_selector(elemento):
        return True
    return False


esperar_botao = partial(esperar_elemento, 'button')
esperar_sucesso = partial(esperar_elemento, '#finished')

url = 'https://selenium.dunossauro.live/aula_09_a.html'

driver = Firefox()

wdw = WebDriverWait(driver, 10)

driver.get(url)

wdw.until(esperar_botao, 'Deu ruim')

driver.find_element_by_css_selector('button').click()

wdw.until(
    esperar_sucesso,
    'A mensagem de sucesso não apareceu'
)

sucesso = driver.find_element_by_css_selector('#finished')

assert sucesso.text == 'Carregamento concluído'

[((15, 16, 15, 51), 'functools.partial', 'partial', ({(15, 24, 15, 40): 'esperar_elemento', (15, 42, 15, 50): '"""button"""'}, {}), "(esperar_elemento, 'button')", False, 'from functools import partial\n'), ((16, 18, 16, 56), 'functools.partial', 'partial', ({(16, 26, 16, 42): 'esperar_elemento', (16, 44, 16, 55): '"""#finished"""'}, {}), "(esperar_elemento, '#finished')", False, 'from functools import partial\n'), ((20, 9, 20, 18), 'selenium.webdriver.Firefox', 'Firefox', ({}, {}), '()', False, 'from selenium.webdriver import Firefox\n'), ((22, 6, 22, 31), 'selenium.webdriver.support.ui.WebDriverWait', 'WebDriverWait', ({(22, 20, 22, 26): 'driver', (22, 28, 22, 30): '10'}, {}), '(driver, 10)', False, 'from selenium.webdriver.support.ui import WebDriverWait\n')]