GoekhanDev
GoekhanDev

Reputation: 518

How to handle a datepicker in selenium (python)?

Im currently on a project which fill the information automaticlly. There is a datepicker on the website which I cant click. How to trigger the datepicker to popup etc.

The website is payoneer.com / Login form

birthbutton = driver.find_elements_by_name("ctl00$cphBodyContent$PersonalDetails1$datepicker5")
birthbutton.click()

Just getting this everytime

AttributeError: 'list' object has no attribute 'click'

Upvotes: 2

Views: 297

Answers (1)

KunduK
KunduK

Reputation: 33384

You have used find_elements_by_name() this will return list. You should use

find_element_by_name()

Now try this.

birthbutton = driver.find_element_by_name("ctl00$cphBodyContent$PersonalDetails1$datepicker5")
birthbutton.click()

I will suggests use webdriverwait.

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.Chrome()
driver.get("https://www.payoneer.com")
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='menu-user-menu-container']//ul//li/a[text()='Register']"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.NAME,"ctl00$cphBodyContent$PersonalDetails1$datepicker5"))).click()

Browser Snapshot:

enter image description here

Upvotes: 2

Related Questions