当“ WebDriver驱动程序”在主要方法之外时,获取“ java.lang.NullPointerException”

时间:2019-07-08 10:33:52

标签: java selenium-webdriver

我不确定java.lang.NullPointerException在主要方法之外时为什么得到WebDriver driver吗?

public class HelloWorldPratice {

static WebDriver driver;

public static void clickonmulitpleelement() {

    //click on help button and handle the alert
    List<WebElement> clickonhelp = driver.findElements(By.linkText("Help"));
    int a2 = clickonhelp.size();
    System.out.println(a2);
    for(int i=0;i<a2;i++) {
        clickonhelp.get(i).click();
        driver.switchTo().alert().accept();
    }

}

public static void main(String[] args) throws IOException, InterruptedException  {
    // TODO Auto-generated method stub

    // open chrome browser
    System.setProperty("webdriver.chrome.driver","D:\\Profiles\\ssaini\\Downloads\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();

0 个答案:

没有答案