-2

Problem i'm currently having is trying to fill out the First Name field out of a sign up page. I've managed to fill out the email name, and select the gender using selenium.

When I try to locate the First Name element using it's Xpath, I get an selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="bb1bda44-91c9-4668-8641-4f3bbbd0c6cd"]"} error

Code:

import selenium
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions

driver = selenium.webdriver.Chrome(executable_path='PATH')


def get_url(url):
    driver.get(url)
    driver.maximize_window()


def fill_data():
    # Find the signup button
    Wait(driver, 30).until(expected_conditions.presence_of_element_located
                           ((By.ID, 'signup-button'))).click()
    # Find the email name box
    email_name = Wait(driver, 30).until(expected_conditions.visibility_of_element_located
                                        ((By.XPATH, "/html/body/onereg-app/div/onereg-form/div/div/form/section/"
                                                    "section[1]/onereg-alias-check/fieldset/onereg-progress-meter"
                                                    "/div[2] "
                                                    "/div[2]/div/pos-input[1]/input")))
    # Enter the email name
    email_name.send_keys('Test')
    # Select gender
    driver.find_element_by_xpath('/html/body/onereg-app/div/onereg-form/div/div/form/section'
                                 '/section[2]/onereg-progress-meter/onereg-personal-info'
                                 '/fieldset/div/div/onereg-radio-wrapper[2]/pos-input-radio/label/i').click()
    # Find the first name box and fill out an account name
    driver.find_element_by_xpath('//*[@id="bb1bda44-91c9-4668-8641-4f3bbbd0c6cd"]')


get_url('https://www.mail.com/')
fill_data()
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • I guess those `id` values are randomly generated. Try using another property that does not change, such as `data-test="first-name-input"`. – Selcuk Oct 30 '19 at 01:13
  • Also, for whatever reason you're doing this, you won't be able to complete the process, because of the requested captcha at the end of the form. You might want to rethink your efforts. – Michele Bastione Oct 30 '19 at 01:20

2 Answers2

0

Few things observed: 1. you id is dynamic 2. You are performing find element with thee first name but you are not sending any text to it

Please find below solution:

from selenium import webdriver 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By 
import time 
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.common.action_chains import ActionChains


# Open Chrome
driver = webdriver.Chrome('C:\New folder\chromedriver.exe')



def get_url(url):
    driver.get(url)
    driver.maximize_window()


def fill_data():
    # Find the signup button
    Wait(driver, 30).until(EC.presence_of_element_located((By.ID, 'signup-button'))).click()
    # Find the email name box
    email_name = Wait(driver, 30).until(EC.visibility_of_element_located
                                        ((By.XPATH, "/html/body/onereg-app/div/onereg-form/div/div/form/section/"
                                                    "section[1]/onereg-alias-check/fieldset/onereg-progress-meter"
                                                    "/div[2] "
                                                    "/div[2]/div/pos-input[1]/input")))
    # Enter the email name
    email_name.send_keys('Tes323t')
    # Select gender
    driver.find_element_by_xpath('/html/body/onereg-app/div/onereg-form/div/div/form/section'
                                 '/section[2]/onereg-progress-meter/onereg-personal-info'
                                 '/fieldset/div/div/onereg-radio-wrapper[2]/pos-input-radio/label/i').click()
    # Find the first name box and fill out an account name
    Wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//input[@data-test='first-name-input']"))).send_keys('Tes323t')


get_url('https://www.mail.com/')
fill_data()
Dipak Bachhav
  • 3,579
  • 1
  • 5
  • 19
0

The desired element is an dynamic element so to fill out the First Name field you have 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://www.mail.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#signup-button"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[data-test='first-name-input']"))).send_keys("live for the hunt")
    
  • Using XPATH:

    driver.get("https://www.mail.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='signup-button']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-test='first-name-input']"))).send_keys("live for the hunt")
    
  • 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:

mail.com

DebanjanB
  • 118,661
  • 30
  • 168
  • 217