Select From A Datepicker In Python
Can anyone help me with the Selenium webdriver (in Python) code to automatically select a date in the input date in the above link. https://www.nseindia.com/products/content/deriv
Solution 1:
You havn't mentioned exactly where you are stuck while automatically sending a date in the <input>
tag. How ever the <input>
tag is having type as text and the following code block works perfect :
Code Block :
from selenium import webdriver driver=webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe') driver.get("https://www.nseindia.com/products/content/derivatives/equities/archieve_fo.htm") print("Page Title is : %s" %driver.title) driver.find_element_by_xpath("//input[@class='textboxdata hasDatepicker' and @id='date']").send_keys("10-04-2018")
Console Output :
PageTitleis : NSE-NationalStockExchange of IndiaLtd.
Snapshot :
References
You can find a couple of relevant detailed discussion in:
Solution 2:
For instance clicking on the 5 of march 2017:
driver.get("https://www.nseindia.com/products/content/derivatives/equities/archieve_fo.htm")
datepicker = driver.find_element_by_id("date")
datepicker.click()
selectMonth = driver.find_element_by_xpath('//select[@class="ui-datepicker-month"]')foroptionin selectMonth.find_elements_by_tag_name('option'):ifoption.text == 'Mar':option.click()
break
selectYear = driver.find_element_by_xpath('//select[@class="ui-datepicker-year"]')foroptionin selectYear.find_elements_by_tag_name('option'):ifoption.text == '2017':option.click()
break
days = driver.find_elements_by_xpath('//a[@class="ui-state-default"]')
days[4].click()
Solution 3:
If Jquery
is included:
driver.execute_script('$("#date_element").val("1977-01-22")')
else:
driver.execute_script('document.getElementById('date_element').value ="1977-01-22"')
Post a Comment for "Select From A Datepicker In Python"