0

I am attempting to fill the field on this website that asks for credit card, however selenium it not allowing me to send keys into the field. I believe this is because you must initially click on the field, but for some reason I can not get it to do that either. Does anyone have any insight?

Website: https://givingday.northeastern.edu/pages/giving-page-2

> Under "Club Sports" click "Give", then click "Archery", then click "Next" to get to CC field

package com.demo.testcases;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.Select;

public class StackOverFlow{

  static WebDriver driver;
  static WebDriverWait wait;

  public static void main(String[] args) throws InterruptedException {

    driver = new ChromeDriver();
    driver.manage().window().maximize();
    wait = new WebDriverWait(driver, 40);
    driver.get("https://givingday.northeastern.edu/pages/giving-page-2");

    Thread.sleep(1000);

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".campaign-tiles-content")));

    scrollDown(driver, "scroll(0,500)");

    Thread.sleep(1000);

    driver.findElement(By.xpath("//a[text()='Club Sports']/parent::div/following-sibling::div[@class='inline-b']"
    + "/descendant::button")).click();

    Thread.sleep(1000);

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".giving-form-billing")));

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//h3[text()='Archery']")));

    Thread.sleep(1000);

    driver.findElement(By.xpath("//button[text()='load more causes']")).click();

    Thread.sleep(1000);

    driver.findElement(By.xpath("//h3[text()='Archery']")).click();

    Thread.sleep(1000);

    driver.findElement(By.xpath("//div[@class='flex-it']/descendant::input")).clear();

    driver.findElement(By.xpath("//div[@class='flex-it']/descendant::input")).sendKeys("1");

    Thread.sleep(1000);

    driver.findElement(By.xpath("//button[text()='Next']")).click();


  }

  public static void scrollDown(WebDriver driver, String YoffSet){
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript(YoffSet);
  }
}
Pritam Maske
  • 2,670
  • 2
  • 22
  • 29
  • Since your CC number and CVV are in iframes with dynamic ID, refer [how to handle dynamically changing iframe id using selenium webdriver] (https://stackoverflow.com/questions/23261495/how-to-handle-dynamically-changing-iframe-id-using-selenium-webdriver) – Dheemanth Bhandarkar Apr 12 '18 at 05:51
  • https://stackoverflow.com/questions/48805576/using-selenium-webdriver-to-interact-with-stripe-card-element-iframe-cucumber – dantesan Feb 27 '20 at 19:34
  • https://stackoverflow.com/questions/48805576/using-selenium-webdriver-to-interact-with-stripe-card-element-iframe-cucumber – dantesan Feb 27 '20 at 19:35

2 Answers2

1

There is a frame on this credit card input. You should first switch to frame then you can send a key.

driver.switchTo().frame(driver.findElement(By.id("spreedly-number-frame-1398")));

driver.findElement(By.id("card_number")).sendKeys(keysTosend);
  • I've tried this and it doesn't work. The 4 digits in the frame id/name are dynamic. – Dheemanth Bhandarkar Apr 13 '18 at 04:09
  • There is no give button under Club Sports. Can you send me a link of the exact page or source codes of the relevant field ( contains frame and credit card label ). We should access the frame with another selector ie: xpath or css – Nahide Ergün Apr 13 '18 at 05:15
0
public void enterCardDetails(String cardNumber) throws Throwable {

    System.out.println(cardNumber.length());// it will print your card length
    for (int i = 0; i < cardNumber.length(); i++) { 
        char c = cardNumber.charAt(i); 
        String s = new StringBuilder().append(c).toString(); 
        driver.findElement(By.xpath("//*[@id='ccard_number']")).sendKeys(s); 
    }
}

Note: You have to define and call cardnumber as per your requirement.

Mohnish
  • 1,010
  • 1
  • 12
  • 20