Home > OS >  How to enter the DOB using Selenium/Python?
How to enter the DOB using Selenium/Python?

Time:04-05

I am not able to enter & select the DD-MM-YY.

Here the html code...

<div >
        <div >
            <input type="date"  name="dob" id="dob"                placeholder="DOB" required>
        </div>
</div>

CodePudding user response:

As per the HTML the <input> is having the type attribute set as date

<input type="date"  name="dob" id="dob" placeholder="DOB" required>

The <input> elements of type="date" create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface. As an example:

<input type="date" id="start" name="trip-start" value="2018-07-22"  min="2018-01-01" max="2018-12-31">

Solution

To send a character sequence of type="date" you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "input.form-control.input_design#dob[name='dob']").send_keys("04-04-2022")
    
  • Using xpath:

    driver.find_element(By.XPATH, "//input[@class='form-control input_design' and @id='dob'][@name='dob']").send_keys("04-04-2022")
    
  • Related