线程“main”中的异常java.lang.NullPointerException IN SELENIUM

时间:2016-12-02 20:42:14

标签: java eclipse selenium import

  1. 获取亚马逊网址
  2. 登录亚马逊
  3. 点击您的帐户
  4. 添加信用卡或借记卡元素
  5. 提供借记卡的信息
  6. 保存。
  7. 任何人都可以解决并解释下面的程序。我在主线程错误中遇到异常

    package amazon;
    
    import static org.junit.Assert.*;
    import java.sql.Driver;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Proxy;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.Select;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    
    public class Inheritancedemo 
    {
        private  WebDriver driver;
            public void impexp(){
            driver=new FirefoxDriver();
            driver.manage().window().maximize();
            driver.get("http://www.amazon.in/");
            WebElement home=driver.findElement(By.id("nav-link-yourAccount"));
            Actions builder=new Actions(driver);
            builder.moveToElement(home).perform();
            driver.findElement(By.xpath(".//*[@id='nav-flyout-ya-signin']/a/span")).click();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.id("ap_email")).sendKeys("jothimani.naveen@gmail.com");
            driver.findElement(By.id("ap_password")).sendKeys("9952709603");
            driver.findElement(By.id("signInSubmit")).click();
        }
    
    public void logusername()
        {
        WebElement home1=driver.findElement(By.xpath(".//*[@id='nav-link-yourAccount']/span[2]"));
            Actions builder=new Actions(driver);
            builder.moveToElement(home1).perform();
            driver.findElement(By.xpath(".//*[@id='nav-flyout-yourAccount']/div[2]/a[1]/span")).click();
        }
        public void vardeclare()
        {
        WebElement home2=driver.findElement(By.xpath(".//*[@id='nav-link-yourAccount']/span[2]"));
            Actions builder3=new Actions(driver);
            builder3.moveToElement(home2).perform();
            driver.findElement(By.xpath(".//*[@id='nav-item-signout']/span")).click();
        }
    }
    package amazon;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.support.ui.Select;
    
    public class Editpage extends Inheritancedemo{
        public WebDriver driver;
        public void edit()
        {
            driver.findElement(By.xpath(".//*[@id='a-page']/div[1]/div/div[3]/div/div/div[2]/div/div[1]/ul/li[2]/span/a")).click();
            Select se=new Select(driver.findElement(By.id("creditCardIssuer")));
            se.selectByIndex(1);
    driver.findElement(By.id("addCreditCardNumber")).sendKeys("4596010006236333");
            driver.findElement(By.id("card-name")).sendKeys("SURESH KUMAR");
            Select se1=new Select(driver.findElement(By.id("newCreditCardMonth")));
            se1.selectByIndex(4);
            Select se2=new Select(driver.findElement(By.id("newCreditCardYear")));
            se2.selectByIndex(5);
            driver.findElement(By.id("enterAddressFullName")).sendKeys("SURESH KUMAR");           
    
    
            driver.findElement(By.id("enterAddressAddressLine1")).sendKeys("ALAGAR APARTMENTS");
            driver.findElement(By.id("enterAddressAddressLine2")).sendKeys("GANDHIJI ST, SINGANALLUR");
            driver.findElement(By.id("enterAddressCity")).sendKeys("COIMBATORE");
            driver.findElement(By.id("enterAddressStateOrRegion")).sendKeys("KERALA");
            driver.findElement(By.id("enterAddressPostalCode")).sendKeys("621405");
            Select se3=new Select(driver.findElement(By.id("enterAddressCountryCode")));
            se3.selectByIndex(4);
            driver.findElement(By.id("enterAddressPhoneNumber")).sendKeys("7373875253");
            driver.findElement(By.xpath(".//*[@id='newCreditCardForm']/table[3]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[6]/td[2]/input"));
            }
    public static void main(String[] args) {
            Editpage e=new Editpage();
            e.impexp();
            e.logusername();
            e.edit();
            e.vardeclare();
    }   
    
    }
    

1 个答案:

答案 0 :(得分:0)

Naveen,从以下变化开始 - 尝试在继承演示类的构造函数中声明Web驱动程序,并将访问修饰符设置为public。 - 不要在子类中再次声明Web驱动程序,即编辑页面类,因为驱动程序声明由超类处理。