The relevant HTML
<div id="datepickerbox" class="ym-gbox-left"><div class="datepick_label"><div id="datepicker" class="hasDatepicker"><div class="ui-datepicker-inline ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="display: block;">
My code
self.driver.find_element(By.XPATH('//*[@id="datepicker"]')).click()
dateWidget = self.driver.find_element(By.ID("ui-datepicker-div"))
rows = dateWidget.find_element_by_tag_name("tr")
columns = dateWidget.find_element_by_tag_name("td")
for cell in columns: self.driver.findElement(By.LINK_TEXT("20")).click()
The error I'm getting
self.driver.find_element(By.XPATH('//*[@id="datepicker"]')).click()
TypeError: 'str' object is not callable
How can I make this work?
According to the “Location elements” section of the manual, By.XPATH
seems to be a string, and the correct usage would be this:
self.driver.find_element(By.XPATH, '//*[@id="datepicker"]')
That also makes sense from the error message, since you are calling By.XPATH
. And the current source also confirms this.
Unfortunately, the Selenium API is not really consistent across different platforms. The syntax you are using, calling By.xpath()
is used by Java, and in C#, you also have to call By.Xpath()
. So it’s just naturally that you get confused when you see other examples where it’s being called and in Python, you suddenly need to pass it. So you shouldn’t blindly trust examples you find on the internet (like this one) but always check for which language they are. And check the documentation and/or the source in doubt.