Home > Software design >  discord login button selenium
discord login button selenium

Time:12-05

im trying to auto login to my discord account and stay online with pyton and selenium

the error : driver.find_element(By.XPATH, '//*[@id="app-mount"]/div[2]/div/div[2]/div/div/form/div/div/div[1]/div[3]/button[2]').click()

this is my code :

import time

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

# Github credentials
username = "email"
password = "password"

# initialize the Chrome driver
driver = webdriver.Chrome("chromedriver")

# head to github login page
driver.get("https://discord.com/login")
time.sleep(3)


# find username/email field and send the username itself to the input field
driver.find_element(By.NAME, 'email').send_keys(username)

# find password input field and insert password as well
driver.find_element(By.NAME, 'password').send_keys(password)
time.sleep(10)
# click login button
driver.find_element(By.XPATH, '//*[@id="app-mount"]/div[2]/div/div[2]/div/div/form/div/div/div[1]/div[3]/button[2]').click()



# wait the ready state to be complete
WebDriverWait(driver=driver, timeout=10).until(
    lambda x: x.execute_script("return document.readyState === 'complete'")
)
error_message = "Incorrect username or password."
# get the errors (if there are)
errors = driver.find_elements(By.CLASS_NAME, "flash-error")
# if we find that error message within errors, then login is failed
if any(error_message in e.text for e in errors):
    print("[!] Login failed")
else:
    print("[ ] Login su")

i didnt find any help in the web

CodePudding user response:

The problem is you are selecting the wrong XPATH. Here's how to find the correct XPATH:

  1. Open enter image description here

    Here's your correct XPATH: //*[@id="app-mount"]/div[2]/div/div[1]/div/div/div/div/form/div[2]/div/div[1]/div[2]/button[2]

    Here's your final code:

    import time
    
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    
    # Github credentials
    username = "email"
    password = "password"
    
    # initialize the Chrome driver
    driver = webdriver.Chrome("chromedriver")
    
    # head to github login page
    driver.get("https://discord.com/login")
    time.sleep(3)
    
    
    # find username/email field and send the username itself to the input field
    driver.find_element(By.NAME, 'email').send_keys(username)
    
    # find password input field and insert password as well
    driver.find_element(By.NAME, 'password').send_keys(password)
    time.sleep(10)
    # click login button
    driver.find_element(By.XPATH, '//*[@id="app-mount"]/div[2]/div/div[1]/div/div/div/div/form/div[2]/div/div[1]/div[2]/button[2]').click()
    
    
    
    # wait the ready state to be complete
    WebDriverWait(driver=driver, timeout=10).until(
        lambda x: x.execute_script("return document.readyState === 'complete'")
    )
    error_message = "Incorrect username or password."
    # get the errors (if there are)
    errors = driver.find_elements(By.CLASS_NAME, "flash-error")
    # if we find that error message within errors, then login is failed
    if any(error_message in e.text for e in errors):
        print("[!] Login failed")
    else:
        print("[ ] Login su")
    
  • Related