【发布时间】:2018-09-21 22:09:35
【问题描述】:
我正在尝试填写该网站上要求信用卡的字段,但是 selenium 不允许我将密钥发送到该字段。我相信这是因为您必须首先单击该字段,但由于某种原因,我也无法让它这样做。有没有人有任何见解?
网址:https://givingday.northeastern.edu/pages/giving-page-2
> 在“俱乐部体育”下单击“给予”,然后单击“射箭”,然后单击“下一步” 进入 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);
}
}
【问题讨论】:
-
由于您的 CC 编号和 CVV 在具有动态 ID 的 iframe 中,请参阅[如何使用 selenium webdriver 处理动态更改 iframe id] (stackoverflow.com/questions/23261495/…)
标签: java selenium selenium-webdriver webdriver