I am unable to click a button using Xpath and Selenium, in this case the aria-label has a unique date which make it perfect to distinguish among some other buttons from a calendar.
This is the HTML code for the button that display the day 5 and the price for that day.
<button type="button" class="CalendarDay__button" aria-label="Choose sunday, february 4 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">4</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>
<button type="button" class="CalendarDay__button" aria-label="Choose monday, february 5 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">5</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>
I am unable to click a button using Xpath and Selenium, in this case the aria-label has a unique date which make it perfect to distinguish among some other buttons from a calendar.
This is the HTML code for the button that display the day 5 and the price for that day.
<button type="button" class="CalendarDay__button" aria-label="Choose sunday, february 4 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">4</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>
<button type="button" class="CalendarDay__button" aria-label="Choose monday, february 5 2018 as your check-in date. It's available." tabindex="0"><div class="calendar-day"><div class="day">5</div><div class="flybondi font-p fare-price"><span>$728*</span></div></div></button>
#Let say I want to click february 5 2018, I tried
dtd0_button = driver.find_element_by_xpath("//button[contains(@class, 'CalendarDay__button') and (@aria-label, 'Choose monday, February 5 2018 as your check-in date. It's available') ]")
dtd0_button.Click()
what is wrong with this approach and I receive the following message 'WebElement' object has no attribute 'Click' if I can Click for any date in the calendar on the web page.
Share Improve this question asked Feb 2, 2018 at 17:10 PetitPetit 231 gold badge1 silver badge6 bronze badges 1-
Maybe try to use chrome dev tools, selecting the button in the source panel, then try
monitorEvents($0)
in console panel to figure out what's going on with events – Gilles Quénot Commented Feb 2, 2018 at 17:14
1 Answer
Reset to default 5There are a couple of errors with your xpath, which make it invalid:
First of all, you have to state
contains
before each condition:"//button[contains(@attribute1, \"content1\") and contains(@attribute2, \"content2\")]"
The
'
inside your xpath isn't escaped. Try the following:"//button[contains(@class,\"CalendarDay__button\") and contains(@aria-label,\"Choose monday, february 5 2018 as your check-in date. It's available.\")]"
Hope it helps. Good luck!