java - 输入信用卡号 Java Selenium

标签 java selenium selenium-webdriver webdriver

我正在尝试填写该网站上要求信用卡的字段,但是 Selenium 不允许我将 key 发送到该字段中。我相信这是因为您必须首先单击该字段,但由于某种原因我也无法让它这样做。有人有任何见解吗?

网站: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);
  }
}

最佳答案

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

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

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

关于java - 输入信用卡号 Java Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49784974/

相关文章:

java - Sonar : You must define the following mandatory properties for unknown not resolved

selenium - Selenium 是否有相对的 CSS 定位器?

java - 如何使用 selenium webdriver 在同一浏览器的另一个选项卡上打开 url?

ruby-on-rails - Selenium 测试在 Ubuntu 和 Mac OSX 上的表现不同是否有原因?

java - 如何使用 selenium webdriver 在测试自动化中使用 Hiptest 发布者

java - 为什么这个JAVA代码无法解析构造函数?

java - NullPointerException 使用 getWindowManager()

pandas - 如何在使用 selenium 和 requests 的数千个下载程序中包含 try 和 Exceptions 测试?

java - TestNG - 如果满足条件,如何从 BeforeSuite 注释强制结束整个测试套件

java - 如何从java代码调用Web服务?