2016-12-02 124 views
0
  1. 獲得亞馬遜網址
  2. 登錄到亞馬遜
  3. 點擊您的帳戶
  4. 添加信用卡或借記卡元素
  5. 給予借記信息
  6. 保存。

任何人都可以解決,爲下面program.I我得到異常在主線程錯誤異常線程「main」顯示java.lang.NullPointerException硒

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("[email protected]"); 
     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(); 
} 

} 
+0

請顯示您的堆棧跟蹤 –

回答

0

納文解釋,先從下面改變 - 嘗試繼承的構造函數內聲明的網絡驅動器具有訪問修飾符的演示類。 - 不要在子類中再次聲明Web驅動程序,即編輯頁面類,因爲驅動程序聲明是由超類處理的。

+0

感謝您的幫助sir.it會解決..現在運行。我得到了答案。 –

+0

@NAVEENKUMAR如果它適合你,請接受答案! – prithvi394

相關問題