Trouble using Selenium to select a date

206 views
Skip to first unread message

Jeff Plank

unread,
Dec 31, 2019, 7:56:00 AM12/31/19
to seleniu...@googlegroups.com
I'm trying to use Selenium with Python to interact with a form at ratespy.com. The code I have so far is:

    from selenium import webdriver

    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import Select

    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("https://www.ratespy.com/best/bmo-bank-of-montreal-mortgage-rates")
    search = driver.find_element_by_id("datepicker")
    driver.implicitly_wait(10)
    search.send_keys("10/10/2019")
    search.submit()

    results = driver.find_elements_by_class_name('find-rate-percent desktop-only')

    print(results[0].text)

The problem is that the form doesn't seem to allow non-numeric characters to be typed in. Therefore, when I try to send "10/10/2019", it shows in the field as "10102019" and doesn't allow me to search properly. When I view the site (https://www.ratespy.com/best/bmo-bank-of-montreal-mortgage-rates) in a browser and I click on the date field, a mini-calendar pops up and I can select the date. Is there a way that I can program selenium to interact with this type of form?

Joe Ward

unread,
Dec 31, 2019, 11:11:04 AM12/31/19
to seleniu...@googlegroups.com
Looks like they've designed it so the datepicker is the only way to do it. It's certainly the only thing that triggers the XHR to bring back different rates from what I can see...

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAGCdmF_dUDY5uy6AXZbpz526vCi9hNnpVVqoaWm%2Byjt981jjyA%40mail.gmail.com.
Message has been deleted

Mike Hetzer

unread,
Dec 31, 2019, 12:47:31 PM12/31/19
to Selenium Users
Sorry,

Well, if you are not testing the actually functionality of the Datepicker for the purposes of this test, you can maybe cheese it with the javascript executor.

I think just

"arguments[0].value = "date"
where arg0 = the datepicker element

Then maybe try submitting the element to trigger the request?

If that doesn't work, you may unfortunately have to make some method to use the datepicker.

Or ask devs to allow typing in the date? ;)

datepicker.jpg
Reply all
Reply to author
Forward
0 new messages