3

I am trying to feed date field using selenium through python. Date field in the website has a date picker with two months shown in that. Here is the detail about that element.

<input id="depart-date-webform-client-form-1642116421-4" class="fcl-datepicker-widget-desktop fcl-datepicker-widget form-text required hasDatepicker" data-type="departing" data-cid="webform-client-form-1642116421-4" autocomplete="off" placeholder="dd/mm/yy" name="submitted[startDate]" value="" size="60" maxlength="128" type="text">

I am placing the cursor in that field, then wait for 2 seconds till the date picker id appears, and trying to feed the date by selecting the date's id.

self.driver.find_element_by_xpath("//input[@id='depart-date-webform-client-form-1642116421-4']").click()
    WebDriverWait(self.driver, 2).until(
            lambda d: d.find_elements_by_id('ui-datepicker-div')[0].is_displayed())
    self.driver.find_element_by_xpath("//div[@id='ui-datepicker-div']//td[@data-year='2016'][@data-month='2']/a[@class='ui-state-default'][text()='19']").click()

I can see that the date is selected successfully in the field when i try to simulate that action by calling firefox through selenium. Next line in my script is this,

self.driver.find_element_by_xpath('//input[@type="submit"]').click()

But I am getting the below error.

selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (136, 15.399993896484375). Other element would receive the click: <td class=" ui-datepicker-other-month ui-datepicker-unselectable ui-state-disabled"></td>

Please point me in the right direction.

Note : Sometime this is working, once in multiple times. Out of 5, 1 time it is working. Rest of the times I am getting this error.

Thanks.

2 Answers 2

1

Several things to be done to fix it:

  • wait for the submit button to be clickable
  • scroll into view of the element
  • improve the submit button XPath expression

The complete working code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Firefox()
driver.maximize_window()
driver.get("http://www.flightcentre.co.nz/")

driver.find_element_by_xpath("//input[@id='depart-date-webform-client-form-1642116421-4']").click()

wait = WebDriverWait(driver, 2)
wait.until(lambda d: d.find_elements_by_id('ui-datepicker-div')[0].is_displayed())

driver.find_element_by_xpath("//div[@id='ui-datepicker-div']//td[@data-year='2016'][@data-month='2']/a[@class='ui-state-default'][text()='19']").click()

wait = WebDriverWait(driver, 10)
search = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[@id = "edit-actions"]//input[@type="submit" and @name = "op"]')))

driver.execute_script("arguments[0].scrollIntoView()", search)
search.click()
Sign up to request clarification or add additional context in comments.

5 Comments

I tried that. Issue is still there.. :( Worked for the first time, after that it didn't work.. :(
@Jeeva okay, it's difficult to guess, could you share the actual URL of the page you are working with? Thanks.
Thanks a lot. That works. Could you please explain whats wrong with my code, so I could learn it.
@Jeeva yeah, the first problem was the xpath locator as me and Morgan have already specified. The scroll into view trick helps to get the button into focus before clicking it. For some reason, even after the calendar is closed, selenium thinks that the button is still covered by the calendar.
1

I think this is your problem, as there are a couple inputs with type=submit. They are not actually on the website but in the dom above the submit you are clicking on.

self.driver.find_element_by_xpath('//input[@type="submit"]').click()

try and also specify the id "edit-submit" and the name "op" I am not entirely sure why Alecxe's answer is not working for you. But I am fairly certain that is where your problem is. If you do a control-f in the dom you can see a button near the top with "input type='submit'".

try:

self.driver.find_element_by_xpath('//input[@type="submit"][@id="edit_submit]').click()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.