0

I am trying to pick a date in this website: https://www.myrealtrip.com/offers/21989

The code I have so far is:

option = selenium.webdriver.ChromeOptions()
option.add_argument(" - incognito")
browser = webdriver.Chrome(executable_path=r"chromedriver.exe")
browser.get('https://www.myrealtrip.com/offers/21989')
calendar = browser.find_element_by_name('.find_element_by_xpath('//*[@id="calendarBtn"]/input')')
date = 2018-04-14, 토요일
calendar2.send_keys(date)

The last line gives an error:

selenium.common.exceptions.InvalidElementStateException: Message: invalid element state

When is it appropriate to use send_key? calendar2 is an object of type WebElement, and so I thought it might work.

Can someone help me? I've also tried clicking on the calendar and clicking on the specific date but found the layout very confusing.

1
  • Update the question with the relevant HTML Commented Apr 10, 2018 at 7:49

2 Answers 2

1

To select for instance 23 of april 2018 you can use this code:

driver.get('https://www.myrealtrip.com/offers/21989') 
driver.find_element_by_id('calendarBtn').click() 
days = driver.find_elements_by_xpath('//a[@class="ui-state-default"]')
days[12].click()
Sign up to request clarification or add additional context in comments.

Comments

0

send_keys won't work since the code on the backend wont allow..the option is disabled...look closely

"input type="text" class="datepicker noselect" name="choice_set[begin_at]" value="2018-04-10, 화요일" readonly="" disabled"

So its better to access the calender by the clicking on it like below..

browser.get('https://www.myrealtrip.com/offers/21989') web_page.find_element_by_css_selector('#calendarBtn').click() sleep(2) web_page.find_element_by_css_selector('#dp1523344028627 > div > div > a.ui-datepicker-next.ui-corner-all').click()

then select whichever date you want by fetching the respective td

2 Comments

I'm afraid #dp1523344028627 is a dynamic id so your selector will not work.
@Frank Thanks didn't noticed that...i think we'll have to move through tags in such case..

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.