Ich habe meinen Code in Java mit Selenium geschrieben. Wenn ich den Code ausführe, wird eine NullPointerException ausgelöst. Überprüfen Sie die Ausnahme unterNullPointerException in meinem Code. Wie man damit umgeht
Exception in thread "main" java.lang.NullPointerException
at AdminInterface.loginApplication(AdminInterface.java:17)
at AdminInterface.main(AdminInterface.java:29)
Mein Code ist wie folgt:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class AdminInterface {
public WebDriver driver;
public void launchApplication() throws Exception
{
System.setProperty("webdriver.ie.driver", "C:\\Users\\rprem\\Downloads\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("https://www.gcrit.com/build3/admin/");
}
public void loginApplication(String Username, String Password)
{
driver.findElement(By.name("username")).sendKeys(Username);
driver.findElement(By.name("password")).sendKeys(Password);
driver.findElement(By.id("tbd1")).click();
}
public void closeBrowser()
{
driver.close();
}
public static void main(String[] args)
{
AdminInterface obj = new AdminInterface();
obj.loginApplication("admin", "[email protected]");
}
}
Sie haben die Methode 'launchApplication' nicht aufgerufen, in der Sie das webdriver-Objekt tatsächlich initialisieren. – Barney
Mögliches Duplikat von [Was ist eine NullPointerException und wie behebe ich sie?] (Https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – JeffC