2016-07-29 14 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; 

    } 

konnte nicht lösen ... jemand mir helfen kann loctTypeNullzeiger erhalten Ausnahme ..?

+0

und wo bekommen Sie eine NPE? – Stultuske

Antwort

0

Bitte überprüfen Sie, ist loctValue nicht null. Und es ist auch gut zu prüfen locter ist not null vor Ihrem try catch Betrieb.

+0

Es wird locvalue und locctype wie gefragt gedruckt. Es gibt ein Problem in der Funktionsaufrufung –

+0

Ändern Sie dieses mit Ihren Werten. – Sirsendu

+0

WebDriverWait wait = neuer WebDriverWait (Treiber, 10); \t wait.until (ExpectedConditions.presenceOfAllElementsLocatedBy (Von \t \t .xpath (locctValue))); – Sirsendu

Verwandte Themen