Selenium / Python – Fill in the login in a pop-up window

Question:

I want to fill in the login of this page with selenium: https://influence.co/go/location-search/top-nl-influencers/city/amsterdam. But it is not sending the keys.

Send_keys

try:
     email = driver.find_element(By.CSS_SELECTOR, "#user_email")
     self.assertTrue(email.is_enabled)
     driver.execute_script("arguments[0].click();", email)
     email.send_keys('[email protected]')

except:
     print("Problem")

Answers:

There is more than one match for that locator. Email field is the second one, so you have to mention like this:

driver.find_element(By.XPATH, "(.//*[@id='user_email'])[2]").send_keys("[email protected]")
Answered By: AbiSaran

I count four elements with id of user_email on the page. One approach is to wait until the modal dialog for new users appears (a few seconds):

    welcome_form = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div#welcome-mat form#new_user")))
    email = WebDriverWait(welcome_form, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#user_email")))
    # set email
    email.send_keys("[email protected]")
    password = welcome_form.find_element(By.CSS_SELECTOR, "input#user_password")
    # set password
    password.send_keys("PASSWORD")
    display_pwd  = welcome_form.find_element(By.CSS_SELECTOR, "button.hideShowPassword-toggle")
    # display password
    display_pwd.click()
    WebDriverWait(welcome_form, 2).until(EC.text_to_be_present_in_element_attribute((By.CSS_SELECTOR, "button.hideShowPassword-toggle"), "class", "hideShowPassword-toggle-hide"))
    # hide password
    display_pwd.click()
Answered By: Easty77