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()
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
:Using
XPATH
:Note : You have to add the following imports :
Browser Snapshot:
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: