最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - i cant click in each button of the page with selenium - Stack Overflow

programmeradmin5浏览0评论
from selenium import webdriver
from selenium.webdrivermon.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

def wait_for_element(driver, by, value, timeout=10, condition=EC.presence_of_element_located):
    return WebDriverWait(driver, timeout).until(condition((by, value)))

def drive_configuration():
    chrome_options = Options()
    arguments = ['--lang=pt-BR', '--window-size=1920,1080']
    for argument in arguments:
        chrome_options.add_argument(argument)
    chrome_options.add_experimental_option('prefs', {
        'download.prompt_for_download': False,
        'profile.default_content_setting_values.notifications': 2,
        'profile.default_content_setting_values.automatic_downloads': 1,
    })
    return webdriver.Chrome(options=chrome_options)

def login(driver):
    try:
        driver.get(
            '=&vaga=&combina=0&cidades%5B%5D=54790&cidades%5B%5D=54860&cidades%5B%5D=55010&cidades%5B%5D=55200&cidades%5B%5D=56720&idade_de=25&idade_ate=30&areas%5B%5D=29&areas%5B%5D=30&areas%5B%5D=54&nivel_escolaridade=5&keyword=')
        time.sleep(5)

        email_xpath = "//input[@id='formLogin_email']"
        email = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, email_xpath)))
        email.send_keys('')
        time.sleep(2)

        password_xpath = "//input[@id='formLogin_pass']"
        password = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, password_xpath)))
        password.send_keys('')
        time.sleep(2)

        login_button_xpath = "//button[@id='btnLogin']"
        login_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, login_button_xpath)))
        login_button.click()
        time.sleep(10)
        print("Login realizado com sucesso.")

    except Exception as e:
        print(f"Erro durante o login: {e}")
        driver.quit()
        exit()

def invite_candidates(driver):
    try:
        invite_button_xpath = '//a[contains(@class, "btnConvidar") and contains(text(), "Convidar")]'
        invite_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, invite_button_xpath)))
        invite_button.click()
        print("Botão 'Convidar' clicado.")

        time.sleep(5)
        fill_fields(driver)

        driver.execute_script(f"document.elementFromPoint(814, 536).click();")
        print("Botão 'Confirmar convite' clicado.")
        print("Candidato convidado com sucesso!")

    except Exception as e:
        print(f"Erro ao convidar candidato: {e}")

def fill_fields(driver):
    driver.execute_script(f"document.elementFromPoint(411, 259).click();")
    print(f"Clicado na coordenada (411, 259)")

    time.sleep(5)
    driver.execute_script(f"document.elementFromPoint(627, 338).click();")
    print(f"Clicado na coordenada (627, 338)")

    driver.execute_script(f"document.elementFromPoint(627, 338).value = 'Whatsapp';")
    print("Campo preenchido com 'Whatsapp'")

    time.sleep(5)
    driver.execute_script(f"document.elementFromPoint(662, 432).click();")
    print(f"Clicado na coordenada (662, 432)")

    driver.execute_script("""
        document.elementFromPoint(662, 432).value = `Olá! Tudo bem?
    Me chamo Kéren e faço parte do RH da PR Promotora, uma empresa referência em atendimento digital aqui no Centro de Criciúma!

    Estamos com uma vaga aberta para atendimento via WhatsApp, e o seu currículo chamou muito a nossa atenção! 
发布评论

评论列表(0)

  1. 暂无评论