How to send key a date with format of MM/YY using python selenium

Viewed 278

Im trying to fill the expiry date of credit card using this code

driver.find_element_by_xpath("//input[@id='authnet-card-expiry']").send_keys('0122')

however its not displaying my expected result

4enter image description here

here's the element

enter image description here

2 Answers

Give a time gap about 1sec between month and year.

Firstly give the number of month and then time sleep during 1sec. Finally send the number of year.

like as below.

driver.find_element_by_xpath('"input path"').send_keys("month")
time.sleep(1)
driver.find_element_by_xpath('"input path"').send_keys("year")

Unfortunately there's not feature in selenium to slow down input while send_keys function, but fortunately, python is quite strong for everything.

Here's solution. but it's seems like there's already good one above:

el = driver.find_element_by_xpath("//input[@id='authnet-card-expiry']")

def type_text(element, text, timeout=0.3):
    import time
    element.clear()
    for s in text:
        time.sleep(timeout)
        element.send_keys(s)


type_text(el, "0122")
Related