Drop Down DatePicker Null ZeigerausnahmeJava

Java-Forum
Anonymous
 Drop Down DatePicker Null Zeigerausnahme

Post by Anonymous »

Bitte helfen Sie mir zu verstehen, warum ich einen java.lang.nullpointerexception für CurrentMonth bekomme. < /p>

Code: Select all

import java.time.Duration;
import java.time.Month;
import java.util.HashMap;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class DatePickerDemo2 {

//user defined method for converting month from string--->Month
static Month convertMonth(String month) {
HashMap monthMap = new HashMap();

monthMap.put("January", Month.JANUARY);
monthMap.put("February", Month.FEBRUARY);
monthMap.put("March", Month.MARCH);
monthMap.put("April", Month.APRIL);
monthMap.put("May", Month.MAY);
monthMap.put("June", Month.JUNE);
monthMap.put("July", Month.JULY);
monthMap.put("August", Month.AUGUST);
monthMap.put("September", Month.SEPTEMBER);
monthMap.put("October", Month.OCTOBER);
monthMap.put("November", Month.NOVEMBER);
monthMap.put("December", Month.DECEMBER);

Month vmonth = monthMap.get(month);

if (vmonth == null) {
System.out.println("Invalid Month...");
}

return vmonth;
}

static void selectDate(WebDriver driver,String requiredYear,String requiredMonth,String requiredDate) throws InterruptedException
{

//select year
WebElement yearDropDown=driver.findElement(By.xpath("//select[@class='ui-datepicker-year']"));
Select selectYear=new Select(yearDropDown);
selectYear.selectByVisibleText(requiredYear);

while(true)
{
//select month
String displayMonth=driver.findElement(By.xpath("//select[@class='ui-datepicker-month']")).getText();

//convert requiredMonth & displayMonth in to Month Objects
Month expectedMonth=convertMonth(requiredMonth);
Month currentMonth=convertMonth(displayMonth);
System.out.println(currentMonth);
//compare
int result=expectedMonth.compareTo(currentMonth);

// 0   months are equla
//>0   future month
//

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post