0

I'm trying to select month, year and date from calendar date-picker. I'm writing my script using pom & page factory approach. I'm not able to pass the date I selected to the variable named TodayDate. Can someone please tell me why TodayDate = null.

             JSClickWithWaitTime(sf.StartDateEST_SF, 60); // clicked on date field

            waitForElementBeVisible(sf.CalendarDateReceived_SF, 100); 
          //JSClickWithWaitTime(sf.StartDateEST_SF, 60);
            Assert.assertTrue(sf.CalendarDateReceived_SF.isDisplayed()); // asserted that the calendar is displayed.            
            selectValueFromDD(sf.MonthFromDateReceived_SF, "Mar");  
            selectValueFromDD(sf.YearFromDateReceived_SF, "2020");
            JSClickWithWaitTime(sf.DayFromStartDate_SF, 3000);
            click(sf.StartDateEST_SF);
            String TodayDate = sf.DayFromStartDate_SF.getAttribute("03/17/2020"); // Save the date into the variable TodayDate
            System.out.println("Today's date is = " +TodayDate); 

Assert.assertEquals("03/17/2020", sf.StartDateEST_SF);

The console will display the below result: Element is Clicked by the JS. Mar is selected 2020 is selected Element is Clicked by the JS. Today's date is = null

4
  • Please add your date picker code and page object code. Use getattribute ('textContent') or getAttribute ('value') to get date if you are using getText()
    – PDHide
    Mar 17, 2020 at 18:20
  • Can you elaborate more on getattribute ('textContent') or getAttribute ('value')?
    – Omar Adam
    Mar 17, 2020 at 18:26
  • Please provide the date picker html DOM , and also your code in page object . Assuming you are using getText() to get value from a field eg day.getText() , change it to day.getAttribute('textContent') ,or day.getAttribute('value') and see either of them works
    – PDHide
    Mar 17, 2020 at 18:40
  • Yes it did. Thank you
    – Omar Adam
    Mar 17, 2020 at 18:57

1 Answer 1

1

Please provide the date picker html DOM , and also your code in page object . Assuming you are using getText() to get value from a field eg day.getText() , change it to day.getAttribute('textContent') ,or day.getAttribute('value') and see either of them works

1
  • 1
    getAttribute('textContent'). actually solved my issue. Thank you PDHide
    – Omar Adam
    Mar 17, 2020 at 18:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.