Search code examples
pythonseleniumxpathcss-selectorscredit-card

How to click on element which contains a credit card number that changes each time with Selenium Python


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;">

Solution

  • 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']