Search code examples
javascriptpythonseleniumselenium-webdrivermaskedtextbox

Python selenium masked field


I'm tying to fill masked phone field +7(___)___-__-__ with python and selenium

<input type="tel" name="PHONE" id="phone" class="js-phone-masked">

My code:

driver.find_element_by_id('phone').click()
time.sleep(2)
driver.find_element_by_id('phone').send_keys(Keys.HOME, '9353232222')

but it filled only firs 2 digs 9 and 3. enter image description here

How i can fill all of this masked field?


Solution

  • I would guess that either there are multiple elements for that phone field, or the underlying javascript is somehow preventing the entire string from writing. You could try sending each digit individually perhaps:

    driver.find_element_by_id('phone').click()
    
    for digit in '9353232222':
        driver.find_element_by_id('phone').send_keys(Keys.END, digit)
        time.sleep(1)