Selenium automation code for “Select the Newly Added Card”

Select the Newly Added Card:

It really depends on the UI of the payment page. If the newly added cards appear at the top of a list, you could select the first card. If they appear at the end or have a distinct identification, you need to use that.

a. For example, if newly added cards appear at the end of a list and have a tag name card:

List cards = driver.findElements(By.tagName(“card”));
WebElement lastCard = cards.get(cards.size() – 1);
lastCard.click();

b. If the newly added card has a unique identification, for instance, the last 4 digits:

driver.findElement(By.xpath(“//*[contains(text(),’1111′)]”)).click();

This is a general pseudo-code and may not work directly on your application due to differences in element identifiers, layout, and behaviors. You need to inspect the elements in your application and adjust the code accordingly.

Leave a comment

Your email address will not be published. Required fields are marked *