1

For example, if I want to use python-selenium to select a specific check-in and check-out date in www.priceline.com, what should I do?

This is the calender html (or you can find it on www.priceline.com)

<input name="checkInDate" pclnfield="ts" pclnoptional="true" preformat="" pclnprepop="false" 
pclnfocusnext="hotel-checkout" type="text" id="hotel-checkin" placeholder="Choose Date" 
autocomplete="off" class="hasDatepicker">

This is my code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
url = 'http://www.priceline.com/' #
driver = webdriver.Firefox()
driver.get(url)
sleep(3)
select = Select(  driver.find_element_by_id('hotel-checkin')  )

Then what?

1 Answer 1

1

First you click at date-picker input:

driver.find_element_by_xpath("//input[@id='hotel-checkin'").click()

then you wait for calendar to appear:

wait.until(lambda driver: driver.find_element_by_xpath("//div[@id='ui-datepicker-div']"))

then you click some date within it:

driver.find_element_by_xpath("//div[@id='ui-datepicker-div']//a[@class='ui-state-default'][text()='HERE_IS_DATE_LIKE_10']")).click() # meaning //div[@id='ui-datepicker-div']//td/a[@class='ui-state-default'][text()='10']

something like that. If you inspect calendar with some browser dev tools, you'll see that each 'day' element is td element with attributes data-year and data-month and you can play around them. Like //div[@id='ui-datepicker-div']//td[@data-year='2014'][@data-month='8']/a[@class='ui-state-default'][text()='10']

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.