TypeError: The 'str' object is not callable when you try to click & ldquo; Datepicker & rdquo;


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

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

TypeError: 'str' object is not callable

How can I make this work?

If you want to use the generic find_element() method - pass two arguments - the By locator type and the locator value:

self.driver.find_element(By.XPATH, '//*[@id="datepicker"]')

Though, it would be cleaner to use the specific find_element_by_xpath() method:


And, even cleaner in this case would be to use "by id" locator: