-1

I'm trying to locate the webelement for the future date but unable to do so. I am finding more than one matching web elements for the same.

I tried:

//*[contains(@class,'flatpickr-day nextMonthDay') and @aria-label='June 3, 2023']

and various other xpath but no luck.

Here is the snapshot of the HTML:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tester
  • 1

1 Answers1

0

Given the HTML:

html

To identify the date June 3, 2023 the xpath which you have used:

//*[contains(@class,'flatpickr-day nextMonthDay') and @aria-label='June 3, 2023']

have certain issues as follows:

  • Today being June 2, 2023, the day June 3, 2023 won't contain the class nextMonthDay.
  • Using contains clause it's better to pass a single attribute value.

Solution

To locate the date June 3, 2023 you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    span.flatpickr-day[aria-label^='June 3']
    
  • Using CSS_SELECTOR:

    span.flatpickr-day[aria-label*='June 3']
    
  • Using XPATH:

    //span[@class='flatpickr-day ' and starts-with(@aria-label, 'June 3')]
    
  • Using XPATH:

    //span[@class='flatpickr-day ' and contains(@aria-label, 'June 3')]
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried all for locators and it says there are "4 elements matching." – tester Jun 05 '23 at 17:45
  • And when I ran my code I got an error: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of -> xpath: //span[@class='flatpickr-day ' and starts-with(@aria-label, 'June 6,')]] (tried for 30 second(s) with 500 milliseconds interval) – tester Jun 05 '23 at 17:47
  • Not sure but I am still unable to click on the date. Can anyone help me with this? – tester Jun 05 '23 at 17:48
  • @tester _it says there are "4 elements matching_: Possibly there are total 4 DatePicker fields with "June 6", so you need to uniquely identify the desired with "June 6" element from the 4 available datepickers. – undetected Selenium Jun 05 '23 at 19:47