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
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()
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: