Reputation: 2179
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.
Upvotes: 3
Views: 1497
Reputation: 3109
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()
Upvotes: 1
Reputation: 473763
Several things to be done to fix it:
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()
Upvotes: 1