0

I am trying to login to the website. But I couldn't fill username and then password. I am stucked on the step filling in a username. I assume that I am picking the wrong class name, but I don't know for sure. I would appreciate your help.

my code:

#
   from selenium import webdriver
   from selenium.webdriver.common.keys import Keys
   from webdriver_manager.chrome import ChromeDriverManager

   driver = webdriver.Chrome(ChromeDriverManager().install())

   url = "https://portal.spryngsms.com/login?redirect=%2F"
   username = "cosmos"
   password = "1234"

   driver.get(url) 

   driver.find_element_by_class_name('form__input-wrapper tw-mb-16 ').send_keys(username)
San
  • 183
  • 8

3 Answers3

1

First thing find_element_by_class_name() accepts single class name Only not multiple class names.

Second thing you need to interact with input element NOT the parent div element.

Instead of class name you should use css selector to identify the input element.

For Username:

driver.find_element_by_css_selector(".form__input-wrapper input[type='text']").send_keys(username)

For password :

driver.find_element_by_css_selector(".form__input-wrapper input[type='password']").send_keys(password)
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • You can use it for multiple class by changing space with dot as it uses css under the hood in python – PDHide Feb 09 '21 at 18:34
  • 1
    @PDHide : Yes It does. But the current scenario if user wants parent tag as well child tag for identifying the element css selector would be ideal. – KunduK Feb 09 '21 at 18:35
0

Use below xpath locators,we are checking the tag input and the value of type attribute:

 //input[@type="password"]

//input[@type="input"]

you can use xpath as

//tag[@attribute=value]

and css as

tag[attribute=value]
PDHide
  • 18,113
  • 2
  • 31
  • 46
0

To send a character sequence to the <input> field you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://portal.spryngsms.com/login?redirect=%2F')
    driver.find_element(By.CSS_SELECTOR, "div.form__inputs div.v-input__control input[type=text]").send_keys("cosmos")
    
  • Using XPATH:

    driver.get('https://portal.spryngsms.com/login?redirect=%2F')
    driver.find_element(By.XPATH, "//span[text()='Gebruikersnaam']//following::div[1]//input").send_keys("cosmos")
    

Ideally, 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://portal.spryngsms.com/login?redirect=%2F')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.form__inputs div.v-input__control input[type=text]"))).send_keys("cosmos")
    
  • Using XPATH:

    driver.get('https://portal.spryngsms.com/login?redirect=%2F')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Gebruikersnaam']//following::div[1]//input"))).send_keys("cosmos")
    
  • 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:

spryngsms

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352