Selenium Web Driver无法找到元素

 长相守短相思洪 发布于 2023-02-12 10:10

我一直在尝试创建一个小项目,将项目放入购物车.它应该进入项目所在的页面并将其添加到购物车.然后,通过使用不同java类中的数据来输入所有计费信息.每次我运行这段代码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;



public class Supreme {

    public static void main(String[] args) throws Exception{
        long start = System.nanoTime();
        WebDriver driver = new FirefoxDriver();

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        driver.get("http://www.supremenewyork.com/shop/hats/selassie-beanie/grey");
        WebElement add = driver.findElement(By.name("commit"));
        add.click();

        driver.get("https://www.supremenewyork.com/checkout");

        AccountInfo a = new AccountInfo();
        a = a.getAccount();

        WebElement name = driver.findElement(By.id("order_billing_name"));
        name.sendKeys(a.getName());

        WebElement email = driver.findElement(By.id("order_email"));
        email.sendKeys(a.getEmail());

        WebElement phone = driver.findElement(By.id("order_tel"));
        phone.sendKeys(a.getPhone());

        WebElement address1 = driver.findElement(By.id("order_billing_address"));
        address1.sendKeys(a.getAddress1());

        WebElement address2 = driver.findElement(By.id("order_billing_address_2"));
        address2.sendKeys(a.getAddress2());

        WebElement city = driver.findElement(By.id("order_billing_city"));
        city.sendKeys(a.getCity());

        WebElement zip = driver.findElement(By.id("order_billing_zip"));
        zip.sendKeys(a.getZip());

        Select state = new Select(driver.findElement(By.id("order_billing_state")));
        state.selectByVisibleText(a.getState());

        Select type = new Select(driver.findElement(By.id("credit_card_type")));
        type.selectByVisibleText(a.getType());

        WebElement credit = driver.findElement(By.id("credit_card_number"));
        credit.sendKeys(a.getCredit());

        Select creditmonth = new Select(driver.findElement(By.id("credit_card_month")));
        creditmonth.selectByVisibleText(a.getExpMonth());

        Select credityear = new Select(driver.findElement(By.id("credit_card_year")));
        credityear.selectByVisibleText(a.getExpYear());

        WebElement cvv = driver.findElement(By.id("credit_card_verification_value"));
        cvv.sendKeys(a.getCVV());

        List check = driver.findElements(By.className("iCheck-helper"));
        for(WebElement w : check){
            w.click();
        }

        WebElement process = driver.findElement(By.name("commit"));
        process.click();
    }
}

我收到此错误:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"order_billing_name"}

谢谢您的帮助!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有