1

I have tried basically everything possible, but I cannot find a way to send keys to the following credit card field. I believe it is because the field needs to be clicked first but I cannot even select the field to click it. Any help is greatly appreciated.

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

HTML from before clicking field:

<form accept-charset="UTF-8" action="javascript:void(0);" id="number-form" onsubmit="return false;">
<label for="card_number" class="visuallyhidden" id="number_label">Card Number</label>
<input type="text" pattern="[0-9]*" name="card_number" id="card_number" autocomplete="off" size="19" style="width: 100%; height: 2.5em; border-radius: 2px; border: 1px solid rgb(226, 226, 226); font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; padding-left: 5%; font-size: 14px; color: rgb(51, 51, 51); box-sizing: border-box;">

HTML from after clicking field:

<form accept-charset="UTF-8" action="javascript:void(0);" id="number-form" onsubmit="return false;" _lpchecked="1">
<label for="card_number" class="visuallyhidden" id="number_label">Card Number</label>
<input type="text" pattern="[0-9]*" name="card_number" id="card_number" autocomplete="off" size="19" style="width: 100%; height: 2.5em; border-radius: 2px; border: 1px solid rgb(226, 226, 226); font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; padding-left: 5%; font-size: 14px; color: rgb(51, 51, 51); box-sizing: border-box;">

<pre id="_h#2" style="white-space: pre-wrap; position: absolute; z-index: -9; visibility: hidden; display: block; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 14px; font-weight: 400; font-style: normal; text-transform: none; text-decoration: none solid rgb(51, 51, 51); letter-spacing: normal; word-spacing: 0px; line-height: normal; text-align: start; vertical-align: baseline; direction: ltr; width: 335px; height: 35px; margin: 0px; padding: 1px 1px 1px 16.75px; border-width: 1px; border-style: solid; overflow: auto; left: 0px; top: 0px;"><span>​</span> </pre>
  • 1
    What did you try? post the code. What happened when you tried it? any exceptions? – Guy Apr 12 '18 at 05:14
  • it has the same id before and after so you should be totally able to use that. Whats your java code to select it? what error you getting? Edit: its because there's a little load wheel on the credit card field when you load the overlay dialog. You need to wait for that to disappear first and/or wait for the credit card field to display rather than trying to set it straight away (guessing thats what's happening) – Simon N Apr 12 '18 at 05:17
  • another thing is that you are in an iframe if you look at the page. You need to look at how to handle iframes... https://www.guru99.com/handling-iframes-selenium.html – Simon N Apr 12 '18 at 05:21
  • The same question has been asked by the OP twice and he doesn't respond to answers (https://stackoverflow.com/questions/49784974/entering-credit-card-number-java-selenium). Also, note that the iframe id is dynamic. @SimonN, the last 4 digits of your answer keep changing on every request. – Dheemanth Bhandarkar Apr 17 '18 at 09:38

3 Answers3

0

based on my assumptions and in the simplest least re-usable way, you will need:

driver.switchTo.frame('spreedly-number-frame-9064')
driver.findElement(by.id('card_number')).click
Simon N
  • 337
  • 2
  • 13
0

Credit card and CVV number fields are in iframe. There are 2 iframe on opened prompt.

Suggestion : You have to switch to iframe in order to perform some operations inside it.

Here is the code that resolves your issue : (Java + Selenium)

public class StackOverFlow {

    static WebDriver driver;
    static WebDriverWait wait;

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


            System.setProperty("webdriver.chrome.driver", "F:\\Automation_Learning\\chromedriver.exe");
            driver = new ChromeDriver();
            driver.manage().window().maximize();
            wait = new WebDriverWait(driver, 40);
            driver.get("https://givingday.northeastern.edu/pages/giving-page-2");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".campaign-tiles-content")));
            Thread.sleep(5000);
            scrollDown(driver, "scroll(0,700)");
            driver.findElement(By.xpath("//a[text()='Club Sports']/parent::div/following-sibling::div[@class='inline-b']/descendant::button")).click();
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".giving-form-billing")));
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//h3[text()='Archery']")));
            driver.findElement(By.xpath("//h3[text()='Archery']")).click();
            scrollDown(driver, "scroll(0,500)");
            wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[class$='secondary-color-background']")));
            driver.findElement(By.cssSelector("button[class$='secondary-color-background']")).click();
            wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("span[class^='step_credit']"))));
            driver.findElement(By.name("first_name")).sendKeys("abc");
            driver.findElement(By.name("last_name")).sendKeys("xyz");
            driver.findElement(By.name("email")).sendKeys("abcxyz@hotmail.com");
            driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id^='spreedly-number-frame']")));
            Thread.sleep(5000);
            driver.findElement(By.xpath("//form[@id='number-form']/descendant::input")).sendKeys("12345678");
        }

        public static void scrollDown(WebDriver driver, String YoffSet){
            JavascriptExecutor jse = (JavascriptExecutor)driver;
            jse.executeScript(YoffSet);
        }
}

Note: : I'm facing internet issue, that's why I have used Thread.sleep(5000);

You can use explicit wait also if you want.

Let me know if you have any concerns related to this.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
-1

Try this hope this will help , driver.switchTo().frame(0); wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath(".//*[@id='card_number']")))); ele.sendKeys("card no.");