[Python] NoSuchElementException ao tentar encontrar elemento com Selenium no Chrome [fechada]

Discussão em 'Python' iniciado por Stack, Novembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    Estou tentando automatizar um fluxo no Chrome com Selenium, mas recebo o erro selenium.common.exceptions.NoSuchElementException ao tentar encontrar um elemento. Já testei usando diferentes seletores (XPath, CSS_SELECTOR) e mesmo assim não consigo encontrar o elemento.

    if onvio == "Incluir":

    # Supondo que o driver já foi inicializado
    novo_usuario = navegador.find_element(By.XPATH, '//*[@id="custom-header"]/div[5]/div/main/app-client-user-container/div/on-content-header/div[1]/div[2]/div/button')

    novo_usuario.click()

    # Inserir nome do usuário
    nome_usuario_element = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, 'document.querySelector("#name")')))
    nome_usuario_element.clear() # Limpa o campo antes de inserir texto
    nome_usuario_element.send_keys(nome_usuario) # Insere o texto

    # Inserir telefone
    telefone_element = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, 'input[id="phone"]')))
    telefone_element.clear() # Limpa o campo antes de inserir texto
    telefone_element.send_keys(telefone) # Insere o texto

    # Inserir email
    email_element = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, 'input[id="email"]')))
    email_element.clear() # Limpa o campo antes de inserir texto
    email_element.send_keys(email) # Insere o texto


    O erro que está dando é esse:

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="custom-header"]/div[5]/div/main/app-client-user-container/div/on-content-header/div[1]/div[2]/div/button"}


    Já tentei XPath, JS Path, CSS.SELECTOR, tentei de tudo e nada foi. Achei que era um problema só com um dos botões, mas depois dele também nada foi.

    Continue reading...

Compartilhe esta Página