Problems with Python Selenium + Datepicker

I try to get the availability / price for every day at https://www.homeaway.pt/arrendamento-ferias/p418841 by clicking on the calendar, checking which days are busy or not clicking the next button so that it can move on to the next month.

I also want to click on the arrival date and then select the discharge date so that I can see the price for it.

I run into problems because I try commands that work in chrome, but then they don't seem to work in selenium.

For instance:

I do:

  self.driver.get(url) wait = WebDriverWait(self.driver, 10) try: elem = wait.until( EC.visibility_of_element_located( ( By.CSS_SELECTOR, "#startDateInput" ) ) ) except TimeoutException: pass else: elem.send_keys(Keys.NULL) 

This seems to open the calendar, and I can also indicate the days available:

 for x in self.driver.find_elements_by_css_selector(".stab-calendar-day.stab-calendar-day-active.stab-calendar-day-selectable.pull-left"): print(x.get_attribute('data-formatted-date')) 

But then, when I want to move to the next active month, it continues to show the same starting month, and this is because it does not work:

 self.driver.find_element_by_css_selector('.stab-calendar-controls-next').click() 

selenium.common.exceptions.NoSuchElementException: Message: cannot find element: {"method": "css selector", "selector": ". stab-calendar-controls-next"}

Any ideas on how I can get the affordability / price of a house for each set of selected days?

+5
source share
1 answer

I'm not sure what exactly you are trying to achieve, but if you are a problem, you simply cannot press the next button. The solution is simple. please change the selector to click the child and it will work. I tested it and it works on firefox.

 driver.find_element_by_css_selector(".stab-calendar-controls-next > i").click() 

And here is all the working code that works. the first time it prints the dates of the current and next. and then the next two months.

 driver = webdriver.Firefox() driver.get("https://www.homeaway.pt/arrendamento-ferias/p418841") wait = WebDriverWait(driver, 10) try: elem = wait.until( EC.visibility_of_element_located( ( By.CSS_SELECTOR, "#startDateInput" ) ) ) except TimeoutException: pass else: elem.send_keys(Keys.NULL) for x in driver.find_elements_by_css_selector(".stab-calendar-day.stab-calendar-day-active.stab-calendar-day-selectable.pull-left"): print(x.get_attribute('data-formatted-date')) # driver.find_element_by_xpath("//*[@class='stab-calendar-controls-next']/i").click() driver.find_element_by_css_selector(".stab-calendar-controls-next > i").click() for x in driver.find_elements_by_css_selector(".stab-calendar-day.stab-calendar-day-active.stab-calendar-day-selectable.pull-left"): print(x.get_attribute('data-formatted-date')) 
0
source

Source: https://habr.com/ru/post/1266174/


All Articles