输入信用卡号Java Selenium

时间:2018-04-11 21:53:16

标签: java selenium selenium-webdriver webdriver

我试图填写这个要求提供信用卡的网站,但是硒它不允许我将密钥发送到现场。我相信这是因为你必须最初点击该字段,但由于某种原因我也无法做到这一点。有没有人有任何见解?

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

  

>   根据" Club Sports"点击"给",然后点击"射箭",然后点击"下一步"   到达CC领域

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);
  }
}

2 个答案:

答案 0 :(得分:1)

此信用卡输入有一个框架。您应该首先切换到框架,然后您可以发送密钥。

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

driver.findElement(By.id("card_number")).sendKeys(keysTosend);

答案 1 :(得分: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); 
    }
}

注意: 您必须根据需要定义并调用cardnumber