我不确定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();