2016-07-29 1 views
-3
public WebElement locater(String locter) 
    { 
     String[] value = locter.split("##"); 
     String loctValue = value[0]; 
     String loctType = value[1]; 



     try { 
      if(loctType.equalsIgnoreCase("XP")) 
      { 


       loct = driver.findElement(By.xpath(loctValue)); 


      } 
      else if(loctType.endsWith("id")) 
      { 
       loct = driver.findElement(By.id(loctValue)); 

      } 
      else if(loctType.equalsIgnoreCase("linkText")) 
      { 
       loct = driver.findElement(By.linkText(loctValue)); 
      } 
      else if(loctType.equalsIgnoreCase("partialLink")) 
      { 
       loct = driver.findElement(By.partialLinkText(loctValue)); 
      } 
      else if(loctType.equalsIgnoreCase("cssSelect")) 
      { 
       loct = driver.findElement(By.cssSelector(loctValue)); 
      } 
      else if(loctType.equalsIgnoreCase("name")) 
      { 
       loct = driver.findElement(By.name(loctValue)); 
      } 
      else if(loctType.equalsIgnoreCase("tagname")) 
      { 
       loct = driver.findElement(By.tagName(loctValue)); 
      } 

     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      System.out.println(e.getMessage()); 
     } 
     return loct; 

    } 

Impossible de résoudre ... quelqu'un peut me aiderObtention d'un pointeur null Exception ..?

+0

et où obtenez-vous un NPE? – Stultuske

Répondre

0

S'il vous plaît vérifier loctType, loctValue n'est pas null. Et aussi son bon à vérifier locter est aussi not null avant votre try catch opération.

+0

il imprime locvalue et loctype comme demandé. Il y a un problème dans la fonction callling –

+0

Modifiez cela avec vos valeurs. – Sirsendu

+0

WebDriverWait wait = new WebDriverWait (pilote, 10); \t wait.until (ExpectedConditions.presenceOfAllElementsLocatedBy (Par \t \t .xpath (loctValue))); – Sirsendu