数据未输入输入字段

Data not enter in input fields

实际上,我有一个网站,我想在其中 运行 购物车功能的完整过程。一切顺利,但当我点击付款方式和 select 借记卡并将数据输入字段时,它不接受。如何将数据放入字段中。

`WebElement BilMethod = wait.until(ExpectedConditions.elementToBeClickable(By.xpath ("/html/body/app-root/div/app-checkout/div/div/div/div[2]/div/div[1]/div/ng-stepper/div/div[2]/div[2]/app-address/div/div[3]/div[3]/div/div"))); BilMethod.click(); Thread.sleep(1000);

    //Clicking on Next Button
    WebElement Clicknext = wait.until(ExpectedConditions.elementToBeClickable(By.xpath
            ("/html/body/app-root/div/app-checkout/div/div/div/div[2]/div/div[1]/div/ng-stepper/div/div[2]/div[2]/app-address/div/div[5]/div[2]/button")));
    Clicknext.click();
    Thread.sleep(10000);
    
    //Clicking on Credit card Method
    WebElement creditcard = wait.until(ExpectedConditions.elementToBeClickable(By.xpath
            ("/html/body/app-root/div/app-checkout/div/div/div/div[2]/div/div[1]/div/ng-stepper/div/div[2]/div[3]"
                    + "/app-payment/div[2]/div[1]/div/div/div[2]/div/ngx-paypal/div/div/iframe[1]")));
    creditcard.click();
    System.out.println("We have selected Credit card method");
    ` Code is working till there butt 

`//输入卡的详细信息 WebElement Card_No = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[1]/div/div/form/div/div[2]/div/div[1]/div/div"))); Card_No.sendKeys("5105105105105100");

    WebElement  expirydate = wait.until(ExpectedConditions.elementToBeClickable(By.id("expiry-date")));    
    expirydate.sendKeys("1225");
    
    WebElement cvc = wait.until(ExpectedConditions.elementToBeClickable(By.id("credit-card-security")));
    cvc.sendKeys("123");
}` 

网站Link:https://vapesuite.allomate.solutions

看,你在这里试图点击一个 iframe(检查 xpath 的最后一部分):

//Clicking on Credit card Method
 WebElement creditcard = wait.until(ExpectedConditions.elementToBeClickable(By.xpath
            ("/html/body/app-root/div/app-checkout/div/div/div/div[2]/div/div[1]/div/ng-stepper/div/div[2]/div[3]"
                    + "/app-payment/div[2]/div[1]/div/div/div[2]/div/ngx-paypal/div/div/iframe[1]")));
    creditcard.click();

不应该这样做,您应该始终切换到 iframe :

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@name, 'zoid__paypal_buttons')]")));

然后点击借记卡或信用卡:

WebElement debitCreditCardButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Debit or Credit Card']")));
debitCreditCardButton.click();

此外,单击 借记卡或信用卡 按钮后,我看到弹出了一个新的 window :

首先像这样切换到 default content :

driver.switchTo().defaultContent();

然后切换到新开的windows:

ArrayList<String> windows = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(windows.get(1));
        
// fill credit cards details now 

更新1:(按顺序)

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@name, 'zoid__paypal_buttons')]")));
WebElement debitCreditCardButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Debit or Credit Card']")));
debitCreditCardButton.click();
driver.switchTo().defaultContent();
                
ArrayList<String> windows = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(windows.get(1));

更新 2:

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@name, 'zoid__paypal_buttons')]")));
        WebElement debitCreditCardButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Debit or Credit Card']")));
        debitCreditCardButton.click();
        driver.switchTo().defaultContent();
        ArrayList<String> windows = new ArrayList<String>(driver.getWindowHandles());
        driver.switchTo().window(windows.get(1));
        driver.manage().window().maximize();
        wait.until(ExpectedConditions.elementToBeClickable(By.id("firstName"))).sendKeys("Zaman 10");