Filling out “First Name” field of a signup page

前端 未结 2 968
情书的邮戳
情书的邮戳 2021-01-29 11:12

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

2条回答
  •  Happy的楠姐
    2021-01-29 12:13

    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:

提交回复
热议问题