Getting Availability From Datepicker
Solution 1:
To click on "Next month" button when datepicker is already opened try following:
defclick_next_month(self):
elements = self.driver.find_element_by_xpath('//span[@class="ui-icon ui-icon-circle-triangle-e"]')
elements[1].click()
To click "Next month" button few times you need to re-define elements
each time, so better to implement both actions (defining list and button click) as method click_next_month()
.
Try and let me know if any issues occurs
Solution 2:
I was able to get this working using driver.execute_script('$( "a.ui-datepicker-next" ).click()')
since everything else was giving me ElementNotVisibleException
and then i noticed that there was javascript involved
<aclass="ui-datepicker-next ui-corner-all"data-handler="next"data-event="click"title="Próximo>"><spanclass="ui-icon ui-icon-circle-triangle-e">Próximo></span></a>
I would rather not use Javascript
or jQuery
directly so if anyone has better suggestions i can try them.
But there are still a few quirks, for example i have to manually reset the calendar each time i get the availability for a certain month.
here is my final code:
def homeaway(self):
MONTH_COUNT = 6
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
driver.maximize_window()
wait = WebDriverWait(driver, 10)
url = 'https://www.homeaway.pt/arrendamento-ferias/p1418427a?uni_id=1590648'
driver.get(url)
count = 0
for month in range(MONTH_COUNT):
# pick start date
start_date = wait.until(EC.visibility_of_element_located((
By.CSS_SELECTOR,
".quotebar-container input[name=startDateInput]")))
start_date.click()
for x in range(count):
driver.execute_script('$( "a.ui-datepicker-next" ).click()')
current_month = driver.find_element_by_css_selector(
".ui-datepicker-month").text
print("current_month:", current_month)
first_available_date = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "#ui-datepicker-div td.full-changeover > a")))
ActionChains(driver).move_to_element(first_available_date).perform()
driver.find_element_by_css_selector(
"#ui-datepicker-div td.full-selected.full-changeover > a").click()
# pick end date (TODO: violates DRY principle, refactor!)
end_date = wait.until(EC.visibility_of_element_located(
(By.CSS_SELECTOR,
".quotebar-container input[name=endDateInput]")))
end_date.click()
first_available_date = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "#ui-datepicker-div td.full-changeover > a")))
ActionChains(driver).move_to_element(first_available_date).perform()
driver.find_element_by_css_selector(
"#ui-datepicker-div td.full-selected.full-changeover > a").click()
# get the calculated price
price = wait.until(EC.visibility_of_element_located(
(By.CSS_SELECTOR, ".price-quote .price-total")))
print(price.text.encode('ascii', 'ignore'))
driver.execute_script('$( "button.ui-datepicker-clear" ).click()')
count += 1
driver.close()
Post a Comment for "Getting Availability From Datepicker"