Issue
I'm not able to click on available date in the calendar. Past dates are greyed out so trying to get today's date and click on it. I have tried execute script, click() and perform() but none of them worked.
today_date = Date.today.strftime('%d')
element = @driver.find_element(:xpath,"//td[contains(@class,\"CalendarDay__default\")][contains(@aria-label, '#{today_date}')]")
#@driver.execute_script("arguments[0].click;", element )
@driver.action.move_to(ele).click(ele).perform
I also tried loop but td element is not displayed as some of elements are greyed out. Not sure how to select displayed elements?
today_date= Date.today.strftime('%d')
date_picker= @driver.find_element(:xpath,"//*[contains(@class,'SingleDatePicker_picker')]")
columns=date_picker.find_elements(:tag_name, "td")
calendar_date=columns.map(&:text).reject(&:empty?)
columns.each do |col|
# This returns true
puts "include date: #{calendar_date.include?today_date}"
if calendar_date.include?today_date
# Elemement is not displayed
puts "td displayed: #{col.displayed?}"
# Not clickable
col.click
end
end
Solution
It's kind of hard to know what will work exactly without being able to work with the actual html, but my guess is that the first thing that is getting matched by that locator is not what you want. Try with this:
element = browser.td(aria_label: Time.now.strftime("%A, %B %d, %Y"))
Or you can select the first non-disabled element regardless of date:
element = browser.td(aria_disabled: 'false')
Edit: just realized your code is Selenium even though the label is Watir. The XPath equivalent to the above are:
".//td[@aria-label=#{Time.now.strftime("%A, %B %d, %Y")}]"
".//td[@aria-disabled='false']"
Answered By - titusfortner
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.