0

I am working on a project with Python and Selenium. In the image you can see the code of the input field in which I try to insert my text.

<input data-v-382b0a6e="" id="expiration" name="expiration" type="text" required="required" data-test="expiration-input" autocomplete="billing cc-exp" dir="auto" class="form-textbox form-textbox-text form-textbox-entered" style="" aria-invalid="true">

Web elements

My first approach was to use the .send_keys(variable) function. The issue there is that the variable month will be inserted in the year. I tried to clear the input field and click into it before, but it didn't help.

WebDriverWait(driver, 30).until(
    EC.presence_of_element_located(
        (By.XPATH, "//*[@data-test='expiration-input']"))).send_keys(expMonth) 

The following image shows the error.

Issue

I also tried to use a Javascript executor to insert a value into this input field, but it has no value attribute and it won't use this attribute.

I have clue what I can do here anymore. Has someone a hint for me how I can insert my text into this field?

Melvin Abraham
  • 2,870
  • 5
  • 19
  • 33

1 Answers1

0

To send a character sequence to the element instead of presence_of_element_located() you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#expiration[name='expiration'][data-test='expiration-input']"))).send_keys(expMonth)
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='expiration' and @name='expiration'][@data-test='expiration-input']"))).send_keys(expMonth)
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352