【问题标题】:Data not enter in input fields数据未在输入字段中输入
【发布时间】:2021-08-30 06:18:44
【问题描述】:

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

`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"))); 比尔方法.click(); 线程.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");
}` 

网站链接:https://vapesuite.allomate.solutions

【问题讨论】:

  • 您的代码工作到哪一行,哪一行没有按预期工作?你遇到什么错误?
  • 是的,当我点击付款方式时,我可以点击付款方式对接显示表单,然后问题是开始输入字段没有获取数据。
  • @cruisepandey : 不行,有没有其他解决办法。

标签: java eclipse selenium selenium-webdriver


【解决方案1】:

看,这里你试图点击一个 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();

另外,一旦点击借记卡或信用卡按钮,我看到弹出一个新窗口:

首先像这样切换到default content

driver.switchTo().defaultContent();

然后切换到新打开的窗口:

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

【讨论】:

  • invalid selector: Unable to locate an element with the xpath expression "//iframe[contains(@name, 'zoid__paypal_buttons')]" 因为以下错误:TypeError: Failed to execute 'evaluate' on 'Document':结果不是节点集,因此无法转换为所需的类型。 (会话信息:chrome=91.0.4472.77)。
  • 尝试你的方法后,出现上述错误。
  • 你能告诉我你在我的解决方案中包含了哪些部分
  • WebElement creditcard = (WebElement) wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("\"//iframe[contains(@name, 'zoid__paypal_buttons')]\"")));信用卡.click(); System.out.println("我们选择了信用卡方式");线程.sleep(5000); WebElement debitCreditCardButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='借记卡或信用卡']"))); debitCreditCardButton.click();
  • 我从您的解决方案中添加的上述代码
猜你喜欢
  • 1970-01-01
  • 2015-06-17
  • 2019-02-21
  • 1970-01-01
  • 1970-01-01
  • 2023-01-17
  • 2020-01-12
相关资源
最近更新 更多