0

I am wrapping locators generic and getting null pointer exception. Please find the below piece of code.

public class WebElementLocator {

     WebDriver driver;
     Properties prop;

    private void getFile(String filePath)
    {
        try {
        FileInputStream fs = new FileInputStream(filePath);
        prop = new Properties();
        prop.load(fs);
        } catch (IOException e) {
            e.getMessage();
        }
    }

    public WebElement getElement(String wElement){
        getFile("ment.properties");
        String eValue = prop.getProperty(wElement);
        String locatorType = eValue.split(":")[0];
        String elementValue = eValue.split(":")[1];
        WebElement we = null;
        switch (locatorType) {
        case "id": we = driver.findElement(By.id(elementValue));
                    break;
        }
        return we;
    }
}

Getting Null pointer exception in below statement

case "id": we = driver.findElement(By.id(elementValue));
                        break;
Ashu123
  • 352
  • 2
  • 6
  • 19

0 Answers0