Sending keys to credit card fields (fields are from stripe) using selenium

0 votes

For the below cases:I tried automating few the test cases for payments. Which is integrated with Stripe.

driver.findElement(By.id("cardNumber")).sendKeys("4242424242424242");

driver.findElement(By.id("cardNumber")).sendKeys(Keys.NUMPAD4);// send keys one by one

Looks like selenium is sending the keys as a string and the card fields allow only integers.

Jun 12, 2018 in Selenium by Martin
• 4,220 points
749 views
I am also having same problem i wanna eneter card details but that card box only accept Interger

1 answer to this question.

0 votes

Below code will help you:

String cnum = "4242424242424242"

Use a for loop to extract single character and use second pointer in your question, as below:

for (char ch : cnum.toCharArray()) {

    switch (Integer.parseInt(String.valueOf(ch))) {

        case 1:

            driver.findElement(By.id("cardNumber")).sendKeys(Keys.NUMPAD1);

            break;

        case 2:

            //and so on...

    }

}
answered Jun 12, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

Is it possible for a website to detect that we are using Selenium with ChromeDriver

Selenium tests for pre-defined javascript variables which ...READ MORE

answered Apr 27, 2018 in Selenium by Meci Matt
• 9,420 points
2,176 views
0 votes
1 answer

How to get the text from a website using selenium?

hey, you can use get.text() method to ...READ MORE

answered Dec 31, 2018 in Selenium by Sudhanshu
868 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
555 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
888 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
551 views
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,130 points
296 views
0 votes
1 answer