1

I have a problem to find element on credit card payment form, which contains a number that changes each time, so please help me to find the way to do it.

This is the element:

<input id="adyen-checkout-encryptedCardNumber-1644589302666" data-fieldtype="encryptedCardNumber" type="text" inputmode="numeric" maxlength="24" autocomplete="cc-number" placeholder="1234 5678 9012 3456" aria-label="Champ du numéro de carte" aria-invalid="true" aria-required="true" aria-describedby="adyen-checkout-encryptedCardNumber-1644589302666-ariaError" class="js-iframe-input input-field" data-type="gsf" style="display: block;">
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
FlutterLover
  • 597
  • 1
  • 11
  • 21

3 Answers3

0

Various locator strategies you can use (as per the DOM provided in the query):

All are xpaths

//input[@data-fieldtype='encryptedCardNumber']

//input[@type='text']

//input[@inputmode='numeric']

//input[@aria-label='Champ du numéro de carte']
Anand Gautam
  • 2,018
  • 1
  • 3
  • 8
  • I use this code but doesnt click def enter_cart_credit_card_number(self, credit_card_number): cart_credit_card_number_id = WebDriverWait(self.driver, 50) cart_credit_card_number_id.until(EC.visibility_of_element_located((By.XPATH, "//input[@data-fieldtype='encryptedCardNumber']"))).click() self.driver.find_element_by_xpath("//input[@data-fieldtype='encryptedCardNumber']").clear() self.driver.find_element_by_xpath("//input[@data-fieldtype='encryptedCardNumber']").send_keys(credit_card_number) – FlutterLover Feb 11 '22 at 14:53
  • This works for me indeed, with the code that you provided in the query: `cc = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//input[@data-fieldtype='encryptedCardNumber']"))) cc.clear() cc.send_keys('5434234567788')` – Anand Gautam Feb 11 '22 at 15:11
  • Not working for me – FlutterLover Feb 11 '22 at 15:18
  • I am sorry, but then need to inspect the website. is it possible to provide the website link? – Anand Gautam Feb 11 '22 at 15:27
  • It's an intern website – FlutterLover Feb 11 '22 at 15:52
0

This HTML...

<input id="adyen-checkout-encryptedCardNumber-1644589302666" data-fieldtype="encryptedCardNumber" type="text" inputmode="numeric" maxlength="24" autocomplete="cc-number" placeholder="1234 5678 9012 3456" aria-label="Champ du numéro de carte" aria-invalid="true" aria-required="true" aria-describedby="adyen-checkout-encryptedCardNumber-1644589302666-ariaError" class="js-iframe-input input-field" data-type="gsf" style="display: block;">

...indicates a Creditcard Number field.

Generally Creditcard Number fields are within an <iframe>. Hence to access the Creditcard Number field you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following locator strategies:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe_css")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[data-fieldtype='encryptedCardNumber'][aria-label='Champ du numéro de carte']"))).send_keys("1234567890")
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"iframe_xpath")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-fieldtype='encryptedCardNumber' and @aria-label='Champ du numéro de carte']"))).send_keys("1234567890")
      
  • 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
    

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Thank you @undetected Selenium for you response it was a frame problem so this is what i do and its works fine for me :

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//*[@id='adyen-card-container']/div/div/div[2]/div[1]/div[1]/label/div/span/iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,"//input[@data-fieldtype='encryptedCardNumber']"))).send_keys("0000111122223333")
##switch parent frame
self.driver.switch_to.default_content()
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(
        (By.XPATH, "//*[@id='adyen-card-container']/div/div/div[2]/div[1]/div[2]/div[1]/label/div/span/iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,"//input[@data-fieldtype='encryptedExpiryDate']"))).send_keys("0228")
##switch parent frame
self.driver.switch_to.default_content()
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it(
        (By.XPATH,  "//*[@id='adyen-card-container']/div/div/div[2]/div[1]/div[2]/div[2]/label/div/span/iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-fieldtype='encryptedSecurityCode']"))).send_keys("123")
    
FlutterLover
  • 597
  • 1
  • 11
  • 21