** Wenn ich diesen Code ausführen. Ich bekomme diesen Fehler Exception in thread "main" java.lang.NullPointerException
. Kann jemand mir sagen, wie man es repariert?Selen-Webdriver mit JAVA
package Insights;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test_getinsights {
static WebDriver driver;
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "C://selenium-2.53.0/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://getinsights.co");
driver.manage().window().maximize();
//Login//
driver.findElement(By.xpath("html/body/div[1]/div/nav/div/div[2]/ul/li[7]/a")).click();
//Login_page//
driver.findElement(By.xpath(".//*[@id='form']/div[1]/input")).sendKeys("[email protected]");
driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/div[2]/input")).sendKeys("airloyal");
driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/form/div[3]/div[2]/button")).click();
//Create_survey//
Thread.sleep(10000);
driver.findElement(By.xpath(".//*[@id='rootId']/div[2]/div[1]/div[4]/div[2]/div/div/button")).click();
//Create_Question//
driver.manage().timeouts().implicitlyWait(700, TimeUnit.SECONDS);
driver.findElement(By.xpath("html/body/div[1]/div/div/div[2]/div[1]/div/button[2]")).click();
driver.findElement(By.xpath(".//*[@id='rootId']/div/div/div[2]/div[2]/div[1]/div[3]/div/div/div/button[2]")).click();
System.out.println("driver=" + driver);
****driver.findElement(By.xpath(".//*[@id='question 14998']/div/textarea")).sendKeys("Which is the best website to learn JAVA?");**** // Null pointer Exception//
driver.findElement(By.xpath(".//*[@id='rootId']/div/div/div[2]/div[2]/div[1]/div[5]/button")).click();
//Post_Question
driver.findElement(By.cssSelector(".clear.openTextStyle.ng-pristine.ng-untouched.ng-invalid.ng-invalid-required")).sendKeys("Java");
driver.findElement(By.cssSelector(".launch-btn.ng-binding")).click();
driver.quit();
driver.close();
}
}
** i die same.Now iam getan haben bekommen „Keine solche Fenster Ausnahme“ ** –
Dies ist ein häufiges Problem. Sie haben explizite Wartezeit oder implizite Wartezeit verwendet driver.manage() .timeouts(). ImplicitlyWait (30, TimeUnit.SECONDS) oder müssen WebDriverWait verwenden wait = new WebDriverWait (driver, 2); und warten –