'How to send text within username input field on a https://discord.com/register webpage with Selenium and Python3

I'm trying to select the username text box in the https://discord.com/register website I tried:

driver.find_element ( by=By.CSS_SELECTOR ...)
driver.find_element ( by=By.CLASS_NAME ...)
driver.find_element ( by=By.CSS_XPATH ...)

They all didn't work . Can anyone help me out with this?



Solution 1:[1]

To send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get('https://discord.com/register')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("text")
    
  • Using XPATH:

    driver.get('https://discord.com/register')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("tamer_mz")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

discord_username

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1