selenium_extensions icon indicating copy to clipboard operation
selenium_extensions copied to clipboard

How do I pick date from date picker (http://www.ksrtc.in/oprs-web/)

Open ghost opened this issue 8 years ago • 3 comments

'''I want to pick date from calendar and want to click on "Search for Bus ''' ||| link to the Website this So far this is my code :

from selenium.webdriver.common.by import By
from selenium_extensions.core import SeleniumDriver
from selenium.webdriver import ActionChains


class KSRTCBOT(SeleniumDriver):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)


    def goto_ksrtc(self):
        self.driver.get('http://www.ksrtc.in/oprs-web/')
        leaving_from = (By.ID, 'fromPlaceName')
        going_to = (By.ID, 'toPlaceName')
        date_of_departure = (By.ID, 'txtJourneyDate')
        pick_date_from_calender = (By.ID, 'ui-state-default')



        self.wait_for_element_to_be_present(leaving_from)
        self.wait_for_element_to_be_present(going_to)
        self.wait_for_element_to_be_present(date_of_departure)
        self.populate_text_field(leaving_from, 'Bengaluru')
        self.populate_text_field(going_to, 'Belagavi')
        #self.populate_text_field(date_of_departure, '11/09/2017')


#my_browser = (browser='chrome', executable_path = '/usr/local/share/chromedriver', headless = True)

bot = KSRTCBOT(browser='chrome', executable_path = '/usr/local/share/chromedriver')

bot.goto_ksrtc()
#bot.shutdown

ghost avatar Sep 09 '17 11:09 ghost

I found date_of_departure to have input field set to readonly. This means the only way to populate it is to click on the date you want in the calendar.

It will require a little bit more code and logic from your, but there is nothings else to do, because that's how the site works.

P.S. I would recommend using XPATH to find a date to click

pythad avatar Sep 09 '17 11:09 pythad

Ya date_of_departure is readonly field I forgot to mention, this question seems similar, however, I'm planning to contribute to this now, for me picking a date from picker seems a little bit tricky. from selenium_extension import date_picker :package: :)

ghost avatar Sep 09 '17 12:09 ghost

The problem is that for each date picker the code will differ. It's possible to write a snippet for Bootstrap date picker or Materialize one, but I think it's almost impossible to write a generic one.

It shouldn't be that hard if you try. It will require a bit of selenium and understanding of how to locate elements by XPATH. Try it on your own and if you have some problems ask a question on Stack Overflow. If no one is willing to help you, feel free to share a link to the question at SO to my email.

pythad avatar Sep 10 '17 09:09 pythad