1

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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tamer_mz
  • 33
  • 4

1 Answers1

0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • this code works thank you . but can you tell me how did you found out that the CSS_SELECTOR is a.btn and can you show me how to select the date of birth inputs they only have class names and i didn't know how to use them . thanks again – tamer_mz Mar 15 '22 at 10:03
  • _CSS_SELECTOR as `a.btn`_ was a typo, corrected it. – undetected Selenium Mar 15 '22 at 11:22